To get started with Docker Engine on Ubuntu, make sure you meet the prerequisites, then install Docker.
OS requirements
To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:
- Ubuntu Jammy 22.04 (LTS)
- Ubuntu Impish 21.10
- Ubuntu Focal 20.04 (LTS)
- Ubuntu Bionic 18.04 (LTS)
Docker Engine is compatible with x86_64
(or amd64
), armhf
, arm64
, and s390x
architectures.
Uninstall Existing Docker Engine
Older versions of Docker went by the names of docker
, docker.io
, or docker-engine
. Uninstall any such older versions before attempting to install a new version:
# Remove existing version of Docker among docker, docker.io, or docker-engine
moalaa@NetDevOps:~$ sudo apt-get remove docker docker-engine docker.io containerd runc
Images, containers, volumes, and networks stored in /var/lib/docker/
aren’t automatically removed when you uninstall Docker.
Install Docker Engine using Docker Repository:
Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
Set up the repository
- 1) Update the
apt
package index and install packages to allowapt
to use a repository over HTTPS:
# Refresh the repositories
moalaa@NetDevOps:~$ sudo apt-get update
moalaa@NetDevOps:~$ sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
- 2) Add Docker’s official GPG key:
moalaa@NetDevOps:~$ sudo mkdir -p /etc/apt/keyrings
moalaa@NetDevOps:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- 3) Use the following command to set up the repository:
moalaa@NetDevOps:~$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine:
- 1) Update the
apt
package index:
moalaa@NetDevOps:~$ sudo apt-get update
Note: If you received a GPG error when running apt-get update
?
moalaa@NetDevOps:~$ sudo chmod a+r /etc/apt/keyrings/docker.gpg
moalaa@NetDevOps:~$ sudo apt-get update
- 2) Install Docker Engine, containerd, and Docker Compose.
# Install most recent version of Docker Engine:
moalaa@NetDevOps:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
- 3)Now check the status of Docker Engined as shown below.
moalaa@NetDevOps:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enab>
Active: active (running) since Sun 2022-10-23 23:46:02 U>
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 11748 (dockerd)
Tasks: 9
Memory: 36.0M
CGroup: /system.slice/docker.service
└─11748 /usr/bin/dockerd -H fd:// --containerd=/>
- 4) In this step, we will verify that the Docker Engine installation is successful by running the
hello-world
image:
sudo docker run hello-world
# Run Hello World Image
moalaa@NetDevOps:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:18a657d0cc1c7d0678a3fbea8b7eb4918bba25968d3e1b0adebfa71caddbc346
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
------
This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
Start Docker Rootless
You have now successfully installed and started Docker Engine. The docker
user group exists but contains no users, which is why you’re required to use sudo
to run Docker commands.
To add your user to the docker
group, run below command:
# Add User to Docker group
moalaa@NetDevOps:~$ sudo usermod -aG docker $USER
Log out and log back in so that your group membership is re-evaluated.
On Linux, you can also run the following command to activate the changes to groups:
moalaa@NetDevOps:~$ newgrp docker
Verify that you can run docker
commands without sudo
.
moalaa@NetDevOps:~$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
Install Docker Compose ¶
The Docker Compose documentation keeps pushing you to Docker Desktop.
Luckily, we don’t even need to download Docker Compose from GitHub as it actually came included during the installation of Docker Engine. The only thing we need to do is link to the executable and grant execution permissions.
sudo ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose
sudo chmod u+x /usr/bin/docker-compose
Top site ,.. amazaing post ! Just keep the work on !
LikeLike