
Introduction
In this tutorial, we will install and use Docker Community Edition (CE) and Docker Compose on Ubuntu. You’ll install Docker and Docker Compose and play with them.
Installing Docker
Docker is an application that simplifies managing application processes in containers. Containers let you run your applications in resource-isolated processes. They’re similar to virtual machines, but containers are more portable, resource-friendly, and dependent on the host operating system.
The Docker installation package available in the official Ubuntu repository may not be the latest version. We’ll install Docker from the official Docker repository to ensure we get the latest version. To do that, we’ll add a new package source, add the GPG key from Docker to ensure the downloads are valid and install the package.
Update your packages:
sudo apt updateNext, install a few prerequisite packages which let apt use packages over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-releaseAdd the GPG key for the official docker repository and add the repository to APT sources.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
This will also update our package database with the Docker packages from the newly added repo.
Now install Docker:
sudo apt install docker-ceDocker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:
sudo systemctl status dockerThe output should be similar to the following, showing that the service is active and running:
# Output
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-07-31 12:02:24 CEST; 9h ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 1524 (dockerd)
Tasks: 62
Memory: 84.7M
CPU: 29.678s
CGroup: /system.slice/docker.service
├─1524 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sockExecuting the Docker Command Without Sudo (Optional)
By default, the docker the command can only be run by the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the docker command without prefixing it with sudo or without being in the docker group, you will get an error. If you want to avoid typing sudo whenever you run the docker command, add your username to the docker group:
sudo usermod -aG docker ${USER}To apply the new group membership, log out of the server and back in, or type the following:
su - ${USER}You will be prompted to enter your user’s password to continue.
If you need to add a user to the docker group that you’re not logged in as, declare that username explicitly using:
sudo usermod -aG docker usernameTo apply the new group membership:
su - usernameInstalling Docker Compose
Docker Compose is yet another useful Docker tool. It allows users to launch, execute, communicate, and close containers with a single coordinated command. Essentially, Docker Compose is used for defining and running multi-container Docker applications.
Start by updating the default repository:
sudo apt updateDownload the latest docker-compose version using the command:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
The command instructs the system to save the file in the /usr/local/bin/ directory under the name docker-compose.
You can check the releases here.
Make the downloaded file executable by changing the file permission with:
sudo chmod +x /usr/local/bin/docker-composeTo verify the installation, check the Docker Compose version by running:
docker–compose --versionDocker Compose should now be installed and ready to use!

Experienced DevOps Engineer proficient in Python, Docker, Kubernetes, CI/CD, and cloud technologies. Specialized in automating processes and building scalable infrastructure for seamless development and deployment.


