Masterclass on Docker

Masterclass on Docker

TASK2.1: The compose should deploy two services (web and DB), and each service should deploy a container as per details below: For web service: --->> php:rc-apache

a. Container name must be php_web.

b. Use image php with any apache tag. Check here for more details https://hub.docker.com/_/php?tab=tags.

c. Map php_web container's port 80 with host port 6000

d. Map php_web container's /var/www/html volume with host volume /var/www/html.

For DB service:

a. Container name must be mysql_web.

b. Use image mariadb with any tag (preferably latest). Check here for more details https://hub.docker.com/_/mariadb?tab=tags.

c. Map mysql_web container's port 3306 with host port 3306

d. Map mysql_web container's /var/lib/mysql volume with host volume /var/lib/mysql.

e. Set MYSQL_DATABASE=database_web and use any custom user ( except root ) with some complex password for DB connections.

*************************************************************************

Solution:

Step 1: Create a directory using “mkdir” command. Get into that directory using “cd” command.

No alt text provided for this image

Step 2: Create docker-compose.yml file using “vim” command. Edit the docker-compose file, first section to define will be the web portion of the stack and next section defines the database.

No alt text provided for this image
No alt text provided for this image

Step 3: Create a directory named “php” under the previous directory. Create index.php file php directory. Edit index.php and add credentials for mysql access.

No alt text provided for this image
No alt text provided for this image

Step 4: Create a Dockerfile using “vim” command. Edit that file put specific keywords that dictate how to build a specific image.

No alt text provided for this image
No alt text provided for this image

Step 5: Install Docker compose.

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

No alt text provided for this image


sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version

No alt text provided for this image

Step 6: Build Docker Container.

No alt text provided for this image

Step 7: Use “docker-compose up “ command to aggregate the output of each container.

No alt text provided for this image

Step 8:

->Use “docker-compose stop” command to Stop the docker-compose.

->Use “docker-compose up -d” command for Detached mode: Run containers in the background.

No alt text provided for this image

Step 9:

-->Use “docker-compose ps” which only shows running containers.

-->Use “curl 192.168.29.22:6000” server-id with 6000 port number.

-->It will show output as “Successfuly Connected to MYSQL”

No alt text provided for this image

#TASK2.2: Dockerfile

1) Webserver

2) This is coming from Docker — -> Content

3) CentOS

**************************************************************************SOLUTION:

Step 1:

-->Create a new directory

-->Create index.html file with some html content “This is coming from Docker” using “vim” command.

-->Create a Dockerfile which includes specific keywords that dictate how to build a specific image.

No alt text provided for this image
No alt text provided for this image

Step 2:

-->Use “systemctl start docker” to start the Docker Service

-->Use “docker build -t webserver .” to create a Docker image from the definition contained in a Dockerfile.

No alt text provided for this image

Step 3: Use “docker run -dit -p 3000:80 webserver” to run the container.

No alt text provided for this image

Step 4:

After that go to the browser and Type => localhost:3000

No alt text provided for this image



To view or add a comment, sign in

More articles by Akash Manikandan

  • Task based on Linux session

    Q.1 Create a file via touch and update that file and also verify the timestamp and output will be redirected to another…

  • SETUP Autoscaling

    Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud…

  • MASTER CLASS ON GIT AND GITHUB

    1. What is the difference between pushing and pulling? Push - pushing sends the recent commit history from your local…

    1 Comment

Explore content categories