M01: Introduction to Operating Systems
TU1: Installing, configuring and exploiting a computer system
ASIX1
Practical Exercise 14 - Docker container  8-04-21

Practical Exercise 14 - Docker containers

GENERAL CONDITIONS

1- Deadline: 25-4-2021.
2- Send your report as a PDF file attached to an e-mail with the following specifications:
     a) E-mail address:
cf(at)collados.org or jordi.binefa(at)fje.edu depending on who is your teacher
     b) File Name:

        b.1)
ASIX1 (English): asix1_surname_name_m01tu01pr14.pdf and asix1_surname_name_m01tu01pr14.odt
        b2.) DAW1 (English): daw1_surname_name_m01tu01pr14.pdf and daw1_surname_name_m01tu01pr14.odt   
     c)
Subject:
        
c.1) ASIX1 (Engish): asix1_surname_name_m01tu01pr14
         c.2)
DAW1 (English): daw1_surname_name_m01tu01pr14
3- Make this report individually.
4- Left, right, top and bottom margins: 2cm.
5- Character format: a) Font: Arial, b) Size: 10, c) Questions typeface: Bold, d) Answers typeface: Regular

 
DOCUMENTATION

1- Basic ideas.
a) What is Docker? --> https://www.youtube.com/watch?v=YFl2mCHdv24  From 0:00 to 0:44
b) Virtual Machine vs Docker -->
https://www.youtube.com/watch?v=YFl2mCHdv24   From 0:45 to 1:56
c) Container, instance, image, build and run -->
https://www.youtube.com/watch?v=YFl2mCHdv24   From 1:57 to 2:16
d) Dockerfile and image -->
https://www.youtube.com/watch?v=YFl2mCHdv24   From 2:17 to 2:41
e) DockerHub
--> https://www.youtube.com/watch?v=YFl2mCHdv24   From 3:53 to 4:16
f) Virtual Machine and Container in a nutshell --> https://deshanigeethika.medium.com/docker-tutorial-a6aa5b41e3ff

2- Installing Docker Engine on Debian Linux
a) Run the following commands:
b) Log out and log in again and check that your user is member of a group called docker (with group ID equal to  997). You can run the command id to check if your user has been properly added to docker.

3- Docker command line. Some basic commands

a) Pulling an image

This command downloads the official image, version 3.0, of Photon OS, which is an open source minimal Linux. 

This command downloads the latest version of an official image, which is called httpd in the DockerHub repository, with the software required to start an Apache web server when a new docker container is created using this image.

b) Showing a list of downloaded images
In this example, you can see that two images called photon and httpd have been downloaded  to your system.

c) Creating and starting a docker container: Basic options



The command creates a new container with the official image of Photon OS version 3. The new container will be called photon3. The application /bin/bash of photon3 is run when the docker container is created and started. The docker container runs until the application /bin/bash is terminated running exit. When the application is terminated, the docker container is stopped but not removed.
 

The command creates a new container with the official image of Photon OS version 3. The new container will be called photon03. No particular application is asked to be run when the docker container is started. The docker container is running always in the background and will be stopped using  docker stop (section 2.e). The docker container is ready to run any application installed using docker exec(section 2.g). The full Container ID is shown by the host machine operating system. Options -i and -t are added in case we wanted to run a  container shell.
The command creates a container with the latest version of the Apache HTTP Server official image. The new container will be called apache2. Port 80 of container is exposed to port 8080 in the host machine. Container runs always in the background. No particular application is asked to be run when the docker container is started. Options -i and -t are added in case we want to run a  container's shell (command interpreter).
d) Showing a list of containers, their Status, Container ID and additional information
Container ID --> Container IDentifier. A unique number that identifies the docker container.
Name --> A unique name that identifies the docker container
Status --> Up means that the docker container is running on your system. Exited means that the docker container has been stopped.
Ports --> What internal port/ports of your docker container is/are exposed to port/ports of your host machine.
Image --> Image used to create the docker container

e) Stopping a docker container

In this example, you can see how to stop a docker container using its Container ID.
In this example, you can see how to stop a docker container using its Name.

f) Starting a docker container

In this example, you can see how to start a docker container using its Name or Container ID.

g) Gaining access to the bash  of a docker container. Running commands in the docker.
In this example, you can see how to gain access to the docker container executing the program bash installed in the container. Option -it is required because we want an interactive session and we want to  work with a terminal and command interpreter. Also,  we want to remain in the command interpreter and run some commands until the command exit is run.


We have run a command (cat  /usr/local/apache2/htdocs/index.html) in the docker container usign the Container ID. This command  shows the contents of index.html in the container. We do not remain, we just run a single com
mand in the container.

We have run a command (ls  -ls  /usr) in the docker container photon03. This command  shows the contents of /usr in the container. We do not remain, we just run a single command in the container.

h) Removing a docker container
In this example:
a) Docker container photon03 is stopped using its Container Name
b) Docker container apache2 is stopped using its Container ID
c) Docker container photon3 is already stopped so, running docker stop is not required.
d) Docker containers photon03 and photon3 are removed using their Container Names
e) Docker container apache2 is removed using its Container ID

i) Removing a docker image