EH1: Linux Lab
ASIX/DAW/DAM-1
Task A5: Deployment (or installation) of application using Docker containers
18-4-24

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

GENERAL CONDITIONS


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)collados.org or jordi.binefa(at)fje.edu depending on who is your teacher
     b) File Name:

        b.1)
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)
Subject:
        
c.1) ASIX1 (Engish): asix1_surname_name_eh1act04
         c.2)
DAW1 (English): daw1_surname_name_
eh1act04
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- 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:

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

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


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

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.

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
In this example:
a) Docker image photon:3.0 is removed
b) Docker image httpd:latest is removed
c) We can see the list of images installed on the host machine before and after running the commands to remove images.
d) We can see the disk space usage of the host machine before and after running the commands to remove images. Check changes in the Used and Available space.
j) Configure Docker to start on boot

9- How to containerize, deploy/install and run a multi-container web application. Working with Docker compose

a) Docker Compose is a tool for running multi-container applications on Docker defined using the Compose file format. A Compose file is used to define how one or more containers that make up your application are configured. Once you have a Compose file, you can create and start your application with a single command: docker compose up

b)
If you want to run a multi-container appication in the backgroud then run: docker compose up -d

c)
In order to containerize, deploy and run an application you should complete the following steps:
d) Example:  Creating and starting a multi-container a web application:
d) In order to stop the multi-container a web application created and started in the previous example:
e) In order to start again the multi-container a web application previously stopped:


PRACTICAL EXERCISE

PART 1

1.-
Create and run a containerized web application (take screenshots of each step):
2- Stop container eh1act04_container_xxyyzz. Check that the container was stopped.  Take a screenshot.

3- Remove your container
eh1act04_container_xxyyzz. Check that the container was removed.  Take a screenshot.

4- Remove image
eh1act04_image_xxyyzz version 1.0. Check that the image was removed.  Take a screenshot.


PART 2

1.- Create and run a multi-container web application (take screenshots of each step):
2- Stop the multi-container application. Check that the containers were stopped.  Take a screenshot.

3-
Start again the multi-container application. Check that the container were started.


PART 3

1.- Download an image of an application called node-red from Docker Hub. Check that the image was downloaded. Take screenshoots.


2.- Create a folder called nodered_data in projects. Afterwards, create a new container to run node-red:
Take a screenshot of your command.

4- Check that container is running on your system. Take a screenshot.

5- Gain access to the application. Take a screenshot.

6- Stop the container. Check that the container was stopped. Take screenshots.

7- Remove the container.
Check that the container was removed. Take screenshots.

8- Remove the image downloaded in question 1.
Check that the image was removed. Take screenshoots.