A-2 DevOps
A-2 DevOps
Assignment No.: -2
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.
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.
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.
docker-compose build
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.
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’
}
}
post {
always {
sh 'docker-compose down -v'
sh 'docker rmi $(docker images -q) -f'
}
}
}