The correction is integrated into the TP (See the green boxes)
Prerequisites #
You must have a machine with Docker installed.
Deployment #
In this section, we will deploy our first Docker container.
Find and Download the Image
We will deploy an Apache web server version 2.4.62. We must find a ready-to-use image and download it.
You must go to a Docker registry. Since we don't have a private registry yet, we will go to a public one, for example:
- Docker Hub: https://hub.docker.com/
- Quay.io: https://quay.io
REMINDER: Depending on the distribution, the Apache server might be called httpd.
So in the case of Docker Hub it gives us:docker pull httpd:2.4.62Deploy the Container
You need to deploy our first container with the following characteristics:- Image: apache version 2.4.62
- Port exposure: 83
- Container name: my-first-container
You can create the container with the command below:
With these explanations:docker run -dit --name my-first-container -p 83:80 httpd:2.4.62- docker run -> command to create a container
- -dit -> combination of flags that run the container in detached(d), interactive(i) mode and allocate a pseudo-TTY. Be careful, flags evolve with your needs but always go simple first.
- -p 83:80 -> expose port 83 on the host and 80 on the guest (container)
- httpd:2.4.62 -> Image used
Check Container Status
You must check that your container is functioning properly. To do this, provide the docker commands for the following actions:- Show running containers
- Show running and stopped containers
- Show only the my-first-container container
- Show containers that have the Label AUTHOR:ROUSSELTM
You can perform the actions with the following commands:
docker psdocker ps -a
This command using '|' covers many cases but to do it properly you should use the -f/--filter option. I invite you to read the other parameters (View). So this gives usdocker ps -a | grep my-first-container
To show containers with labels we cannot use '|' because our ps output does not show labels. We are therefore forced to use filtersdocker ps -f name=my-first-containerdocker ps --filter 'label=AUTHOR=ROUSSELTM'Container Verification
You must find the command to test the proper functioning of the web server container.WARNING: A running container is not necessarily a functioning container. You must check its logs and outputs.
You can verify with the following command:
You should see the text 'It works!' in the output.$ curl http://localhost:83 -s
Optimization #
In this section, we will optimize our first Docker container.
Build a second, lighter container
As mentioned during the courses, official images must be used in priority, especially the most optimal ones. You must choose another, more size-optimized image.
You can create a lighter container with Alpine.
REMINDER: A good practice is to use Alpine images as soon as they are available.
So in the case of Docker Hub it gives us:docker run -dit --name my-second-container -p 84:80 httpd:2.4.62-alpineCompare the disk usage of the two containers
You must find a command that shows only the two containers with their disk usage, knowing that both image names contain 'my-'
You can do this with the command below:
With these explanations:$ docker ps -f name=my- -s CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE 410b6a032a0c httpd:2.4.62-alpine 'httpd-foreground' 19 seconds ago Up 17 seconds 0.0.0.0:84->80/tcp my-second-container 2B (virtual 62.9MB) 0865fe7c9e31 httpd:2.4.62 'httpd-foreground' 3 hours ago Up 3 hours 0.0.0.0:83->80/tcp my-first-container 2B (virtual 148MB)- -s -> show disk usage
Difficulty level : ●●○○○ (2/5)
Course Glossary
DevOps
A culture, movement, and set of practices designed to unify software development (Dev) and IT operations (Ops).
API Gateway
A gateway that acts as a single entry point for all requests to a microservices architecture. It handles routing, security, and rate limiting.
Architecture
The overall structural design of an IT system, defining its various components, their relationships, and the principles guiding its evolution.
Artifact
The final outcome of a software compilation or build process, such as a .jar file, a zip archive, or a Docker image, ready for deployment.
Repository
A centralized storage location. This can refer to a source code repository (e.g., Git) or an artifact and binary repository (e.g., Harbor, Nexus, Arti...
Docker
An open-source platform designed to make it easier to create, deploy, and run applications by isolating them into portable, lightweight software conta...