Docker has become a must-have for developers and system administrators looking to simplify the deployment of their applications. By encapsulating applications in lightweight containers, Docker enables unprecedented portability, efficiency and scalability. In this article, we’ll explore in detail the benefits of Docker, how to install it quickly, and some useful commands for managing your containers.
Introduction to Docker
What is Docker?
Docker is an open source platform that automates the deployment of applications in software containers. These containers are lightweight, fast and portable, and contain everything an application needs to run: code, runtime, system libraries, etc.
Why use Docker?
Here are some of the main advantages of Docker :
- Portability: Docker containers can be run anywhere – on your local machine, in the cloud, or on on-premise servers – without having to worry about differences in system configuration.
- Isolation: Each container operates in isolation, which means that applications do not overlap or cause conflicts.
- Resource efficiency: Unlike virtual machines, containers share the same system kernel and don’t need a complete OS, which significantly reduces resource usage.
- Ease of management: Docker simplifies the process of updating and deploying applications, thanks to tools like Docker Compose.
Quick installation of Docker
Installing Docker
To install Docker on a Debian-based distribution such as Ubuntu, run the following command:
sudo apt update && sudo apt install docker.io apparmor -y
Installing Docker Compose
Docker Compose is a tool that lets you define and manage multi-container applications. To install it, use the following commands:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.19.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Checking the installation
To check that Docker Compose has been correctly installed, run :
docker-compose --version
Useful commands for Docker
Creating and launching containers with Docker Compose
To create and launch containers defined in a docker-compose.yml
file, use :
sudo docker-compose up --build --remove-orphans -d
Deleting containers with Docker Compose
To stop and delete containers, networks and volumes defined in the docker-compose.yml
file :
sudo docker-compose down
Updating a container
To update a container, follow these steps:
- Stop containers :
- List Docker images :
- Delete the image of the container to be updated:
- Recreate and relaunch containers :
Accessing a container via SSH
To access a running container via SSH :
sudo docker exec -it container-name /bin/bash
Note: Use /bin/sh
if /bin/bash
is not available.
sudo docker exec -it container-name /bin/sh
View container logs
To monitor a container’s logs in real time :
sudo docker logs -f container-name
Conclusion
Docker offers a powerful and flexible solution for deploying and managing applications. Whether you’re a developer, system administrator or just curious, Docker can transform the way you work with software. Feel free to try out the commands above and explore further the possibilities offered by this revolutionary technology.
If you have any questions or comments, leave them below! Don’t forget to share this article if you found it useful.
—
Note: The controls and instructions mentioned in this article are based on a typical configuration and may need to be adjusted to suit your specific environment.