Docker: An essential part of DevOps Philosophy

Yassine LAKHDACHI
ENSIAS IT
Published in
5 min readJul 4, 2022
DevOps cycle

Have you ever heard about containerization and its technologies? Do you often see posts on social media and groups about Docker? Containerization? Virtualization? Docker image? Docker-file? Docker-compose?

In a few minutes, we will discover all the details about this technology, then we could say that we have been introduced to the DevOps field (another story).

What is Docker?

Before starting our talk about Docker, you must understand the concept of a container! A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. Docker allows you to embed an application in one or more software containers that can run on any machine server, whether physical or virtual machine, we can run it on Linux and Windows servers. The amazing thing is that Docker is an open-source technology offered by Docker.Inc in 2013, it intended to facilitate applications deployment.

Talking about Docker, you should assimilate the difference between virtualization and containerization?

Virtualization allows via a hypervisor, to simulate one or more physical machines, and run them in the form of virtual machines (VM) on a server or a terminal. These VMs integrate an OS on which applications are executed (This is not the case with the software container). The container calls directly on the OS of its host machine to make its system calls and run its applications, hence its extreme lightness. In the case of Linux, Docker containers exploit a component of the Linux kernel called LXC (or Linux Container). In Windows Server format, they are backed by an equivalent brick, called Windows Server Container. Engine Docker normalizes these bricks through APIs to run applications in standard containers, which are then portable from one server to another.

What is a Dockerfile?

A Dockerfile is a script that automatically creates containers on the Docker platform. A Dockerfile is a text document that contains all the commands you could call on the command line to assemble an image.

Wait, wait…..what is an image? So Docker images act as the starting point when using Docker. An image resembles a snapshot in virtual machine (VM) environments. A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template :).

An example of a Dockerfile of Django workspace

Docker containers, created by Dockerfiles, can run on any Linux server. Container environments for applications are created using Docker images, which can be built either by executing commands manually or automatically through Dockerfiles. Linux and Windows programs can run inside Docker containers. Using Dockerfiles, you can create an automated container build that executes several command-line instructions in succession, step by step.

run multiple containers as a single service: Docker Compose

Docker Compose is software used for defining and running multi-container Docker applications. It can handle various containers simultaneously in the production, staging, development, testing, and CI environment.

Docker-compose icon

Docker Compose works by applying rules defined in a docker-compose.YAML file. The YAML file configures the application’s services and includes rules specifying how you want them to run. With the file in place, you can start, stop, or rebuild all the services using a single command. Additionally, you can check the status of a service, display log outputs, and run one-off commands.

Now let’s go ahead and create your first Docker Compose file. All Docker Compose files are YAML files. You can create one using your favorite text editor(for me Visual Studio Code):

docker-compose file

Now let’s take a close look at the various details of this file:

1/- The database and web keyword are used to define two separate services. One will be running your MySQL database and the other will be your Nginx web server.

2/- The image keyword is used to specify the image from Docker Hub(a cloud-based repository in which Docker users and partners create, test, store, and distribute container images) for your MySQL and Nginx containers.

3/- For the database, we are using the ports keyword to mention the ports that need to be exposed for MySQL.

4/- We also specify the environment variables for MySQL which are required to run MySQL.

Now let’s run your Docker Compose file using the following command:

command to build the compose file

Once executed, all the images will start downloading and the containers will start automatically.

the build of images

Resources that I used to master Docker:

1/- TechWorld With Nana

2/- Docker Essentials: Learn Hands-on Containerization and Orchestration with Docker Ecosystem (Docker, Compose, and Swarm)

3/- Learn Docker — DevOps with Node.js & Express

4/- Tutorialspoint

5/- Docker Tutorial for Beginners

6/ Docker deep dive and RKE

--

--

Yassine LAKHDACHI
ENSIAS IT

Software Engineering Student, Cloud/DevOps Enthusiast