Docker Installation Guide
Docker is an open platform that allows developers to build, ship, and run applications inside containers. A container packages an application together with its runtime, libraries, and configuration so it behaves consistently across environments. The same container image can run on a local Linux machine, a staging server, or a production cluster with predictable results. This approach reduces environment related issues and makes deployments more structured and reproducible.
Docker vs Docker Compose
When working with containerized applications, two names appear constantly: Docker and Docker Compose. They are closely related and often used together, yet they serve different responsibilities. Understanding the distinction helps you structure projects correctly and avoid confusion in daily workflows.
Docker is a container engine. Its primary responsibility is to build container images and run containers from those images. When you use commands such as
docker build,docker run, ordocker ps, you are interacting directly with Docker Engine. It handles image creation, container lifecycle management, networking, and storage at the container level. In simple terms, Docker runs individual containers.Docker Compose is a tool designed to define and manage multi container applications. Instead of working with containers one by one, Docker Compose allows you to describe an entire application stack in a single YAML configuration file, usually named
compose.yaml. In that file, you define services, networks, and volumes that belong to the application. With a single command such asdocker compose up, Docker Compose creates and starts all defined services together.
To make the difference explicit: Docker manages containers. Docker Compose manages applications that consist of multiple containers.
Install Docker Engine using apt repository
The recommended installation method on Linux is through Docker's official repository. This ensures you install the latest stable Docker Engine version.
Setup the repository
Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker apt repository.
Install dependencies:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyringsAdd Docker's official GPG key:
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.ascAdd Docker repository to apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
Afterward, you can install and update Docker from the repository.
Install Docker Engine
To install the latest version, run:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin
The Docker service starts automatically after installation.
To verify that Docker is running, use:
sudo systemctl status docker
Some systems may have this behavior disabled and will require a manual start:
sudo systemctl start docker
Verify Docker Engine
Verify that the installation is successful by running the hello-world image:
sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
Manage Docker as a non-root user
By default, Docker commands require root privileges. To run Docker without sudo, create the docker group and add your user to it.
sudo groupadd docker
sudo usermod -aG docker $USER
Log out and log back in to apply the new group membership.
docker run hello-world
If the container runs successfully without sudo, Docker is configured for non root usage.
Install Docker Compose using apt repository
Docker Compose is installed as a Docker plugin in modern setups.
Set up the repository. Find distribution-specific instructions in:
Ubuntu | CentOS | Debian | Raspberry Pi OS | Fedora | RHELUpdate the package index, and install the latest version of Docker Compose:
For Ubuntu and Debian, run:
sudo apt-get update
sudo apt-get install docker-compose-pluginFor RPM-based distributions, run:
sudo yum update
sudo yum install docker-compose-plugin
Verify that Docker Compose is installed correctly by checking the version.
docker compose version
This enables the docker compose command.
The older standalone docker-compose binary still exists and can be installed manually, but it is considered a legacy option and is not recommended for new environments.
0 Comments