LabDocker
LabDocker
Task 1
Use a Dockerfile to create the below image:
a. Create an image with GIT installed.
b. After the image creation tag your image as Qu1:v1.0. What do you observe?
c. Create a container based on that image but use the flag to run the container in the
background.
d. Use the docker attach command (and describe its usability) to enter the container. Verify
that git is installed.
Task 2
Read and execute the demo code https://docs.docker.com/compose/gettingstarted. Use the code
for the app and create image based on instructions.
For this question, you need to change the Dockerfile and the compose file.
We want to move the app build configuration from the Dockerfile to the compose file.
Specifically;
a) inside the Dockerfile you should only have the below commands:
FROM python:3.9-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
Task 3
You are given a skeleton code inside the Qu3 folder.
For this question, you should complete the code inside the docker-compose file.
You need to create an application that runs a php server and you need to connect it with mysql
database. Also, we need to create another container that can run the phpMyAdmin.
a) Write a script to create the image for the mysql server having the following characteristics:
(i) Derived from image mysql
(ii) Define restart policy as always
(iii) Define port “9906:3306”
(iv) Define environment variables
MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: MYSQL_DATABASE
MYSQL_USER: MYSQL_USER
MYSQL_PASSWORD: MYSQL_PASSWORD
b) Write a script to create the image for phpMyAdmin having the following characteristics:
(i) Derived from image phpmyadmin
(ii) Define restart policy as always
(iii) Define export port, different form the one of the php server.
(iv) Define the dependency on the database image.
(v) Define environment variables
PMA_HOST: db
c) When you have completed the compose file and started the app, you will see that a folder
php/src is created. Copy the php source codes that are included in the Qu3 folder to php/src.
You can visit the http://localhost:8000 to view the website. Also, you can login as a database
admin through http://localhost:admin_port, using root as username and
MYSQL_ROOT_PASSWORD as password.