Installing Docker Engine on Ubuntu
Installing Docker Engine on Ubuntu
To get started with Docker Engine on Ubuntu, make sure to meet the prerequisites and follow the installation steps.
Prerequisites
If you manage firewall settings using ufw or Firewalld, be aware that exposing container ports using Docker bypasses these firewall rules.
OS Requirements
To install Docker Engine, you need one of the following 64-bit versions of Ubuntu:
- Ubuntu Montic 23.10
- Ubuntu Jammy 22.04 (LTS)
- Ubuntu Focus 20.04 (LTS)
The Docker Engine for Ubuntu is compatible with the x86_64 (or amd64), armhf, arm64, s390x, and ppc64le (ppc64el) architectures.
Removing Previous Versions
Before installing Docker Engine, you need to remove conflicting packages. Distro maintainers provide unofficial distributions of Docker packages in APT. To install the official version of Docker Engine, you must first remove these packages.
Removing Unofficial Packages
- docker.io
- docker-compose
- docker-compose-v2
- docker-doc
- podman-docker
- containerd
- runc
To remove these packages, execute the following command:
sudo apt-get remove docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runcNote: apt-get may report that these packages are not installed.
Removing Stored Data
Deleting the /var/lib/docker/ directory does not automatically remove stored images, containers, volumes, and networks. If you want to start fresh and clean up existing data, refer to the Docker Engine removal section.
Installation Methods
You can install Docker Engine using various methods as needed.
Installing via Docker apt Repository
Set up the Docker repository before installing Docker Engine on a new host machine. Then you can install and update Docker from the repository.
Set up the Docker apt repository:
Adding Docker’s official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc Adding the repository to Apt sources: echo “deb [arch=$(dpkg —print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo “$VERSION_CODENAME”) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
Note: If you’re using Ubuntu derivative distributions like Linux Mint, use $(. /etc/os-release && echo “$VERSION_CODENAME”).
Install the Docker packages:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginTesting Docker Engine
To verify that Docker Engine is installed successfully, run a test image:
sudo docker run hello-worldThis command downloads a test image and runs it in a container. Once the container runs, it prints a confirmation message and exits.
Next Steps
Start developing with Docker. Learn how to build new applications using Docker.