0% found this document useful (0 votes)
12 views

LabDocker

Uploaded by

johariqbal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

LabDocker

Uploaded by

johariqbal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Docker Lab

What should you submit?


A source code for each question. Please create a different folder for each t a s k as
follows:

In Qu1 directory, you should have


o Dockerfile
In Qu2 directory, you should have
o app.py,
o docker-compose.yml,
o Dockerfile,
o requirements.txt,
In Qu3 directory, you should have
o Docker-compose.yml,
o Dockerfile,
o php/src/index.php,
o php/src/insert.php

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.

Hint: Use alpine as base image.

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

b) To update the compose, you need to


(i) create a network that through this network the containers can communicate
(ii) run the app, and
(iii) create a volume so that the web service can store the code. Note that we removed the
COPY command from the Dockerfile.
Hint:
• • Use the commands “docker network/volume ls” to view the resources you have created.

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.

You might also like