0% found this document useful (0 votes)
18 views6 pages

A-2 DevOps

The document describes a Dockerfile and Docker Compose file used to build and run a PHP application and MySQL database using Docker containers. It provides the contents and explanations of the Dockerfile and docker-compose.yml file, and steps to build the Docker images, push to Docker Hub, and run the containers.

Uploaded by

Muneeb ur rehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

A-2 DevOps

The document describes a Dockerfile and Docker Compose file used to build and run a PHP application and MySQL database using Docker containers. It provides the contents and explanations of the Dockerfile and docker-compose.yml file, and steps to build the Docker images, push to Docker Hub, and run the containers.

Uploaded by

Muneeb ur rehman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name: - Muneeb ur Rehman

Registration Number: - FA20-BCS-072


Course title: - DevOps

Assignment No.: -2

Submitted by: -Muneeb ur Rehman


Dockerfile

What is a Dockerfile?

A Dockerfile is a text document that contains all the commands a user could call on the command
line to assemble an image. Docker can build images automatically by reading the instructions
from a Dockerfile.

Contents of the Dockerfile

Dockerfile for PHP Application (Dockerfile-php):

Dockerfile for MySQL Database (Dockerfile-mysql):


Docker Compose File

What is a Docker Compose file?

Docker Compose is a tool for defining and running multi-container Docker applications. With
Compose, you use a YAML file to configure your application's services. Then, with a single
command, you create and start all the services from your configuration.

Contents of the docker-compose.yml file


Building the Docker Images:

To build the Docker images for both the PHP application and the MySQL database, you use the
docker-compose build command. This command looks for a docker-compose.yml file in the
current directory and builds the images as per the specifications provided in the file.

Command to Build the Images:

docker-compose build

Pushing docker image to docker-hub

Containers up and running


On Docker Hub:

Running the Containers:

With Docker Compose, running containers is streamlined. Use the following command to start up
all the services defined in the docker-compose.yml file:

This command starts all the containers as defined in the compose file in detached mode, meaning
they'll run in the background.

Web Application Running:

Once your containers are up and running, your application should be accessible via a web
browser. The URL will be the public IP address of your AWS EC2 instance where the Docker
containers are hosted, appended with the port number.

http://13.53.214.166:8080/index.php
Part 2: Pipeline script

pipeline {
agent any

environment {
IMAGE_PHP = 'php-app'
IMAGE_MYSQL = 'mysql-db'
}

stages {
stage('Checkout Code') {
steps {
git ‘https://github.com/mUne3b1/DevOpsass.git’
}
}

stage('Build Docker Images') {


steps {
script {
docker.build("${env.IMAGE_PHP}", '-f Dockerfile-php .')
}
script {
docker.build("${env.IMAGE_MYSQL}", '-f Dockerfile-mysql .')
}
}
}

stage('Run Docker Compose') {


steps {
dir("${env.COMPOSE_DIR}") {
sh 'docker-compose up -d'
}
}
}
}

post {
always {
sh 'docker-compose down -v'
sh 'docker rmi $(docker images -q) -f'
}
}
}

You might also like