EH1: Linux Lab
Task A5: Deployment (or installation) of application using Docker containers

Task A5: Deployment (or installation) of applications using Docker containers


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

ASIX1 (English): asix1_surname_name_eh1act04.pdf and asix1_surname_name_eh1act04.odt
        b2.) DAW1 (English): daw1_surname_name_eh1act04.pdf and daw1_surname_name_eh1act04.odt   
c.1) ASIX1 (Engish): asix1_surname_name_eh1act04
DAW1 (English): daw1_surname_name_
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


1- How to deploy (or install) an application

Nowadays there 3 typical ways to deploy a web application or install a system application:
2- Disadavantages of  deploying/installing applications on physical machines, virtual machines and container

a) The disadvantages of
deploying/installing application on physical computer with regard virtual machines or containers are the following:

The disadvantages of
deploying/installing application on virtual computers
with regard containers are the following::

Generally speaking deployment/Installation via containers means that your application are
faster, more portable, more efficient (cpu, ram, disk..) and hihghly scalable. The only problem is isolation. The best way to provide isolation among applications is working with virtual machines. But isolation provides by containers is betters than isolation provided by physical machines.

3- Container engines

a) A container engine, also known as a container runtime, is a software component responsible for creating, managing, and running containers on a host system.

b) One of the most popular container engines is Docker Engine. Docker Engine utilizes the Docker daemon dockerd  to manage containers and images, along with the Docker CLI docker for interacting with the daemon.

c) Other container engines include Containerd, cri-o, LXD or  Podman. These container runtimes offer similar functionalities to Docker Engine but may differ in implementation details and features.

4- Basic ideas about Docker containers
a) List of basic ideas you should know and remember: Docker, Container, Image, Build, Run, Dockerfile, DockerHub
b) What is Docker? -->  From 0:00 to 0:44
c) Virtual Machine vs Docker -->   From 0:45 to 1:56
d) Container, instance, image, build and run -->   From 1:57 to 2:16
e) Dockerfile and image -->   From 2:17 to 2:41
f) DockerHub
-->   From 3:53 to 4:16
g) Virtual Machine and Container in a nutshell -->

5- Docker compose

Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to use a simple YAML file to configure the services, networks, and volumes required for your application, and then spin up all the containers with a single command. Here's how Docker Compose works:
  1. Define Your Application Services: In a docker-compose.yml  file, you specify the services that make up your application. Each service typically corresponds to a container, and you define various settings such as the Docker image to use, environment variables, ports to expose, volumes to mount, and dependencies between services.

  2. Environment Variables and Overrides: Docker Compose allows you to use environment variables and override settings in the docker-compose.yml file using a separate .env file or environment variables passed directly to the docker-compose command. This flexibility enables you to customize your application's configuration for different environments (e.g., development, testing, production).
  3. Start Your Application: Once you have defined your docker-compose.yml file, you can use the docker-compose up command to start all the containers defined in the file. Docker Compose will create the necessary networks and volumes, pull Docker images (if not already available locally), and start the containers in the correct order based on dependencies.

  4. Manage Your Application: Docker Compose provides commands for managing your multi-container application, such as:

    •  Starting -> docker-compose start

    • Stopping -> docker-compose stop

    • Reestarting -> docker-compose restart

    • Viewing logs -> docker-compose logs

    • Scaling ->  docker-compose scale

Docker Compose simplifies the process of running multi-container applications locally or in development and testing environments. It's especially useful for applications that consist of multiple interconnected services, such as web servers, databases, caches, and message brokers, by providing a convenient way to define, configure, and manage the entire application stack with a single tool.

6- Installing and enabling  Docker Engine on Debian Linux

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.

c) Enable the docker service -->  sudo systemctl enable docker

7- How to containerize, deploy/install and run a web application

a) In order to containerize, deploy and run an application you should complete the following steps:
b) Example:  Contanairezing a web application:

8- 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 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) Running commands or applications in a docker container.
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