Uninstall old versions
Before you can install Docker Engine, you need to uninstall any conflicting packages.
Distro maintainers provide unofficial distributions of Docker packages in APT. You must uninstall these packages before you can install the official version of Docker Engine.
The unofficial packages to uninstall are:
docker.io
docker-compose
docker-compose-v2
docker-doc
podman-docker
Moreover, Docker Engine depends on containerd
and runc
. Docker Engine bundles these dependencies as one bundle: containerd.io
. If you have installed the containerd
or runc
previously, 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.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
apt-get
might report that you have none of these packages installed.
Images, containers, volumes, and networks stored in /var/lib/docker/
aren't automatically removed when you uninstall Docker. If you want to start with a clean installation, and prefer to clean up any existing data, read below uninstall Docker Engine section.
Uninstall Docker Engine
-
Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
-
Images, containers, volumes, or custom configuration files on your host aren't automatically removed. To delete all images, containers, and volumes:
$ sudo rm -rf /var/lib/docker $ sudo rm -rf /var/lib/containerd
$ rm ~/.docker
You have to delete any edited configuration files manually.
Install from a package
If you can't use Docker's apt
repository to install Docker Engine, you can download the deb
file for your release and install it manually. You need to download a new file each time you want to upgrade Docker Engine.
-
Select your Ubuntu version in the list.
-
Go to
pool/stable/
and select the applicable architecture (amd64
,armhf
,arm64
, ors390x
). -
Download the following
deb
files for the Docker Engine, CLI, containerd, and Docker Compose packages:containerd.io_<version>_<arch>.deb
docker-ce_<version>_<arch>.deb
docker-ce-cli_<version>_<arch>.deb
docker-buildx-plugin_<version>_<arch>.deb
docker-compose-plugin_<version>_<arch>.deb
-
Install the
.deb
packages. Update the paths in the following example to where you downloaded the Docker packages.$ sudo dpkg -i ./containerd.io_<version>_<arch>.deb \ ./docker-ce_<version>_<arch>.deb \ ./docker-ce-cli_<version>_<arch>.deb \ ./docker-buildx-plugin_<version>_<arch>.deb \ ./docker-compose-plugin_<version>_<arch>.deb
The Docker daemon starts automatically.
-
Verify that the Docker Engine installation is successful by running the
hello-world
image.$ sudo service docker start $ 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.
You have now successfully installed and started Docker Engine.
Pull from a different registry
By default, docker pull
pulls images from Docker Hub. It is also possible to manually specify the path of a registry to pull from. For example, if you have set up a local registry, you can specify its path to pull from it. A registry path is similar to a URL, but does not contain a protocol specifier (https://
).
The following command pulls the testing/test-image
image from a local registry listening on port 5000 (myregistry.local:5000
):
$ docker image pull myregistry.local:5000/testing/test-image
Registry credentials are managed by docker login.
Docker uses the https://
protocol to communicate with a registry, unless the registry is allowed to be accessed over an insecure connection. Refer to the insecure registries section for more information.
Setup registry mirrors:
{ "registry-mirrors": [ "https://dockerproxy.com", "https://docker.m.daocloud.io", "https://docker.anyhub.us.kg", "https://docker.awsl9527.cn" ] }
zzh@ZZHPC:/etc/docker$ sudo systemctl daemon-reload zzh@ZZHPC:/etc/docker$ sudo service docker restart zzh@ZZHPC:/etc/docker$ sudo service docker status zzh@ZZHPC:/etc/docker$ docker run hello-world