SM1: Open-source operating systems
ASIX/DAW/DAM-1
Task A11: Deployment or installation of application using Docker containers
16-1-26

Task A11: Deployment or installation of applications using Docker containers

GENERAL CONDITIONS

Deadline ASIX1: 29-1-2026
Deadline ASIX1: 2-2-2026
 
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.

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) Check that a new group called docker has been added to the system.

c) Display status of a new service installed on your machine called docker

sudo systemctl status docker

and check that the service is started and enabled.

d) Add your default users to the docker group: sudo gpasswd -a $USER docker

e) Log out and log in and check that your user is now member of 984 (docker).

f) Check that a management utility called docker has been installed on your machine and check its version. Run: docker --version


7- 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 and published 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 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.

h) Running commands or applications in a docker container.


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.

i) 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

j) 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.
k) Configure Docker to start on boot

8- How to containerize, deploy  and gain access to a single-container web application

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

or alternatively, if you experience any problem downloading php:8.4-apache:

d) Additional information:  https://docs.docker.com/get-started/02_our_app/


8- How to share data between a host machine and a docker container using volumes

a) Command --> docker  run  --name  <container_name>  -i  -t  -d  -p  <port_host:port_container>  -v  <folder_host_machine:folder_docker_container>  <image_name> where:
b) Example:



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 and published 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). Folder ./webapp of the host machine shares date with folder /var/www/html of the  container.

c) If you want to check the list of available volumes on your system run the following command: docker volume ls


9- How to containerize, deploy and gain access to 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 easily create, start, stop, modify or remover your application with a single command.


b)
In order to containerize, deploy and run an application using multiple containers, you should complete the following steps:

c)
Example: 
Creating and starting a multi-container a web application:
e) In order to stop the multi-container a web application created and started in the previous example:
f) In order to start again the multi-container a web application previously stopped:
g) In order to stop and remove the multi-container web application:

PRACTICAL EXERCISE

PART 1

1.-
Install docker on your system and add your default user to the group docker. Show clearly that:


2.-
Create and run a containerized web application:

3-
Checking PART 1:
 

PART 2

1.- Create a folder called sm1act11p2. Change to sm1act11q2 and create a folder called nr_data.

2.-
Download an image of an application called node-red from a repository called nodered/node-red using docker pull.

3.- Create a docker container with the following characteristics:
a) Name: nr
b) Container can be accessed with the help of its internal .bash
c) Container runs in the background
d) Container exposes and publish internal port 1880 to por 1880 in the virtual machine.
e)
Folder ./nr_data of the host machine shares date with folder /data of the docker container.
f) Container is created from image nodered/node-red.

4.- Check the list of available volumes on your system running: docker inspect nr | grep nr_data

5- Check the IP address of your virtual machine.

6- Access node-red using  a web browser from your physical computer. In the address bar type: http://<ip_address_of_your_virtual_machine>:1880 where
<ip_address_of_your_virtual_machine> is the IP address found in point 4.


7- Checking PART 2:

PART 3

1.- Follow steps in section DOCUMENTATION -  Point 9: How to containerize, deploy and gain access to a multi-container web application. Working with Docker compose and deploy the application sm1act11q3.

2- Checking PART 3: