Preface
This document details the complete process of installing Docker on Ubuntu Server 22.04, including resolving problems encountered during the process. Hope it will help readers.
The key to the installation process is to read the official documentation./engine/install/ubuntu/
Step 1: Uninstall the conflicting package
Before installing Docker Engine, you need to uninstall all conflicting packages. The release maintainer provides an unofficial distribution of the Docker package in APT. You must uninstall these packages before you can install the official version of Docker Engine.
Unofficial packages to uninstall include:
- docker-compose
- docker-compose-v2
- docker-doc
- podman-docker
In addition, Docker Engine relies oncontainerd
andrunc
. Docker Engine bundles these dependencies into a package:. If you installed it before
containerd
orrunc
, uninstall them to avoid conflicts with the versions bundled with Docker Engine.
Run the following command to uninstall all conflicting packages:
for pkg in docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
apt-get
You may report that you do not have these packages installed.
Notice: When uninstalling Docker, the storage in/var/lib/docker/
Images, containers, volumes and networks in . If you want to start with a fresh installation and want to clean up all existing data, readUninstall Docker Enginepart.
Step 2: Update the system package
First, update existing software packages in the system:
sudo apt update
Step 3: Install the dependency package
Install the necessary dependency packages for obtaining the repository over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Step 4: Add Docker GPG Key to the University of Science and Technology of China
To ensure the authenticity and integrity of the downloaded Docker package, we need to add Docker's GPG key:
sudo mkdir -p /etc/apt/keyrings sudo curl -fsSL /docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/ sudo chmod a+r /etc/apt/keyrings/
Possible problems
-
Unable to download GPG keys:
-
error message:
curl: (6) Could not resolve host:
- Solution: Search for other mirror sites online. Reference connection: /m0_46471328/article/details/138043873
Background knowledge: The GPG key is used to verify the integrity and authenticity of the software package and ensure that the downloaded software package has not been tampered with.
-
error message:
Step 5: Add Docker University of Science and Technology Mirror Stable Version Software Source
We use the mirror source of the University of Science and Technology of China to speed up the download speed:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/] /docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt// > /dev/null
Possible problems
-
Mirror source addition failed:
-
error message:
bash: /etc/apt//: Permission denied
-
Solution: Make sure to use
sudo
Run the command to obtain the necessary permissions.
Background knowledge: The software source is the server address of the storing software packages. Adding Docker's image source can speed up downloading and improve reliability.
-
error message:
Step 6: Update the package again
After adding a new Docker software source, update the package index in the system again:
sudo apt update
Possible problems
-
Update failed:
-
error message:
Failed to fetch /docker-ce/linux/ubuntu/dists/focal/stable/binary-amd64/Packages 404 Not Found
-
Solution:examine
/
Whether the mirror source address in the file is correct, and confirm that the mirror source of the University of Science and Technology of China is available.
Background knowledge: Updated package index is to let the system know the latest package information, including packages in newly added software sources.
-
error message:
Step 7: Install the latest version of Docker
Install Docker and its dependencies:
sudo apt install docker-ce docker-ce-cli
Possible problems
-
Installation failed:
-
error message:
E: Unable to locate package docker-ce
- Solution: Make sure that the image source in the previous step has been correctly added and updated the package index.
Background knowledge:Docker is an open source platform for developing, delivering, and running applications. It packages the application and its dependencies into a standardized unit called a container.
-
error message:
Step 8: Configure Docker to use mirror accelerator (hub)
Since accessing Docker Hub in China may have speed and connection problems, we configure Docker to use Tencent Cloud's mirror accelerator:
sudo mkdir -p /etc/docker echo '{ "registry-mirrors": [""] }' | sudo tee /etc/docker/ > /dev/null
Possible problems
-
Unable to access the mirror accelerator:
-
error message:
dial tcp: lookup on 127.0.0.53:53: no such host
- Solution: Make sure the configured mirror accelerator address is correct and accessible, and other addresses may need to be replaced. Address 127.0.0.53:53 is a local DNS cache service, usually provided by the system's systemd-resolved service.
Background knowledge: Mirror accelerator can increase the speed of pulling images from Docker Hub, especially in domestic network environments.
-
error message:
Step 9: Restart the Docker service
To make the configuration take effect, restart the Docker service:
sudo systemctl daemon-reload sudo systemctl restart docker
Step 10: Verify Docker installation
Run a simple Docker container to verify that the installation is successful:
sudo docker run hello-world
Possible problems
-
Docker Hub cannot be accessed:
-
error message:
denied: requested access to the resource is denied unauthorized: authentication required
- Solution: Log in to Docker Hub through the following command:
sudo docker login
Follow the prompts to enter your Docker Hub username and password.
-
error message:
-
Network connection issues:
-
error message:
dial tcp: lookup on 127.0.0.53:53: no such host
- Solution: After configuring the mirror accelerator and restarting the Docker service, try to pull the image again.
Background knowledge:
hello-world
The mirror is a very small image used to verify that Docker is working properly. -
error message:
View Docker service logs in real time
You can use the following command to view the Docker service logs in real time:
sudo journalctl -u -f
The purpose of this command is:
-
sudo
: Run commands with super user permissions. -
journalctl
: Command to view system logs. -
-u
: Specify viewing the logs of the Docker service. -
-f
: View log output in real time, similar totail -f
。
Additional resources
- Docker official documentation
- Docker Hub
- Docker Getting Started Guide
- Docker Community Support
Summarize
Through the above steps, I successfully installed and configured Docker on Ubuntu Server 22.04. The main thing is the mirror address problem. By adjusting the configuration file and replacing the mirror source, I successfully solved these problems. Hopefully you are the same.
This is all about installing Docker on Ubuntu Server 22.04. For more relevant steps for installing Docker in Ubuntu Server, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!