Ubuntu Docker Installation
Docker Engine-Community supports the following Ubuntu versions:
- Xenial 16.04 (LTS)
- Bionic 18.04 (LTS)
- Cosmic 18.10
- Disco 19.04
- Other newer versions...
Docker Engine - Community supports x86_64 (or amd64), armhf, arm64, s390x (IBM Z), and ppc64le (IBM Power) architectures.
Automatic Installation Using the Official Installation Script
The installation command is as follows:
# Download and execute the official Docker installation script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Start Docker service
sudo systemctl start docker
sudo systemctl enable docker
Manual Installation
Uninstall Old Versions
Older versions of Docker are called docker, docker.io, or docker-engine. If they are installed, please uninstall them:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
The current version is called the Docker Engine-Community package docker-ce.
To install Docker Engine-Community, two methods are introduced below.
Install Using the Docker Repository
Before installing Docker Engine-Community on a new host for the first time, you need to set up the Docker repository. Afterwards, you can install and update Docker from the repository.
Set Up the Repository
Update the apt package index.
$ sudo apt-get update
Install apt dependency packages for fetching the repository over HTTPS:
$
sudo
apt-get install
\
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add Docker's official GPG key:
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
Use the following command to set up the stable repository
echo
\
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable"
|
\
sudo
tee
/
etc
/
apt
/
sources.list.d
/
docker.list
/
dev
/
null
sudo
apt-get update
Install Docker Engine-Community
Update the apt package index.
$ sudo apt-get update
Install the latest version of Docker Engine-Community and containerd, or move on to the next step to install a specific version:
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
To install a specific version of Docker Engine-Community, list the available versions in the repository and then choose one to install. List the versions available in your repository:
$
apt-cache
madison docker-ce
docker-ce
|
5
:18.09.1~
3
0
~ubuntu-xenial
|
https:
//
mirrors.ustc.edu.cn
/
docker-ce
/
linux
/
ubuntu xenial
/
stable amd64 Packages
docker-ce
|
5
:18.09.0~
3
0
~ubuntu-xenial
|
https:
//
mirrors.ustc.edu.cn
/
docker-ce
/
linux
/
ubuntu xenial
/
stable amd64 Packages
docker-ce
|
18.06.1~ce~
3
0
~ubuntu
|
https:
//
mirrors.ustc.edu.cn
/
docker-ce
/
linux
/
ubuntu xenial
/
stable amd64 Packages
docker-ce
|
18.06.0~ce~
3
0
~ubuntu
|
https:
//
mirrors.ustc.edu.cn
/
docker-ce
/
linux
/
ubuntu xenial
/
stable amd64 Packages
...
Use the version string in the second column to install a specific version, for example 5:18.09.1~3-0~ubuntu-xenial.
$ sudo apt-get install docker-ce= docker-ce-cli= containerd.io
To test whether Docker was installed successfully, enter the following command; if the following information is printed, the installation succeeded:
$
sudo
docker run hello-world
Unable to
find
image
'hello-world:latest'
locally
latest: Pulling from library
/
hello-world
1b930d010525: Pull
complete
Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image
for
hello-world:latest
Hello from Docker
!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1
. The Docker client contacted the Docker daemon.
2
. The Docker daemon pulled the
"hello-world"
image from the Docker Hub.
(
amd64
)
3
. The Docker daemon created a new container from that image
which
runs the
executable that produces the output you are currently reading.
4
. The Docker daemon streamed that output to the Docker client,
which
sent it
to your terminal.
To try something
more
ambitious, you can run an Ubuntu container with:
$ docker run
-it
ubuntu
bash
Share images, automate workflows, and
more
with a
free
Docker ID:
https:
//
hub.docker.com
/
For
more
examples and ideas, visit:
https:
//
docs.docker.com
/
get-started
/
Install using a Shell script
Docker on get.docker.comand test.docker.com provides convenient scripts for quickly installing the edge and test versions of Docker Engine-Community. The source code of the scripts is in the docker-install repository. It is not recommended to use these scripts in production environments; before using them, you should understand the potential risks:
-
The scripts need to run as root or with sudo privileges. Therefore, before running the script, you should carefully inspect and review it.
-
These scripts attempt to detect the Linux distribution and version and configure the package management system for you. In addition, the scripts do not allow you to customize any installation parameters. From Docker's point of view, or from the perspective of your own organization's guidelines and standards, this may result in unsupported configurations.
-
These scripts will install all dependencies and recommendations of the package manager without confirmation. This may install a large number of packages, depending on the current configuration of the host.
-
The script does not provide an option to specify which version of Docker to install; instead, it installs the latest version released in the edge channel.
-
If Docker has already been installed on the host using another mechanism, do not use the convenience script.
This example uses the get.docker.com script on to install the latest version of Docker Engine-Community on Linux. To install the latest test version, use test.docker.com instead. In each command below, replace every occurrence of get with test.
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
If you want to use Docker as a non-root user, you should consider adding the user to the docker group in a way similar to the following:
$ sudo usermod -aG docker your-user
Uninstalling Docker
Remove the installation package:
sudo apt-get purge docker-ce
Delete images, containers, configuration files, and so on:
sudo rm -rf /var/lib/docker