Ubuntu Docker Installation

Ubuntu Docker Installation

Docker Engine-Community supportes the following versions of Ubuntu:

  • Xenial 16.04 (LTS)
  • Bionic 18.04 (LTS)
  • Cosmic 18.10
  • Disco 19.04
  • Other updated versions of ……

Docker Engine – Community support on x86_64 (or amd64) armhf, arm64, s390x (IBM Z), and ppc64le (IBM’s Power) architectures.

Automatically install Docker using the official installation script

The installation command is as follows.

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

You can also use the daocloud one-click install command at –

curl -sSL https://get.daocloud.io/docker | sh

Install Docker manually

Uninstall an older version

Older versions of Docker are called docker, docker.io or docker-engine. If they are installed, uninstall them at

$ sudo apt-get remove docker docker-engine docker.io containerd runc

The current package called Docker Engine-Community is docker-ce.

To install Docker Engine-Community, the following two methods are described.

Installing using the Docker repository

Before installing Docker Engine-Community for the first time on a new host, you need to set up a Docker repository. After that, you can install and update Docker from the repository.

Set up the repository

Update the apt package index.

$ sudo apt-get update

Install the apt dependency package for fetching the repository via HTTPS –

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

Add the official GPG key for Docker.

$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 Verify that you now have the key with the fingerprint by searching for the last 8 characters of the fingerprint.

$ sudo apt-key fingerprint 0EBFCD88

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

Use the following command to set up a stable repository –

$ sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
  $(lsb_release -cs) \
  stable"

Install Docker Engine-Community

Update the apt package index.

$ sudo apt-get update

Install the latest version of Docker Engine-Community and containerd, or go 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 your repository and select one to install. List the versions available in your repository at –

$ 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
  ...

Install a specific version using the version string in the second column, e.g. 5:18.09.1~3-0~ubuntu-xenial.

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

To test whether Docker is successfully installed, enter the following command and the following message will be printed:

$ 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/

Installing with Shell Scripts

Docker provides convenience scripts on get.docker.com and test.docker.com that will quickly install the edge and test versions of Docker Engine-Community. The source code for the scripts is available in the docker-install repository. It is not recommended to use these scripts in a production environment, and you should be aware of the potential risks before using them.

  • The scripts require running root or having sudo privileges. Therefore, the scripts should be carefully checked and reviewed before running them.
  • These scripts attempt to detect Linux distributions and versions, and configure the package management system for you. In addition, the scripts do not allow you to customize any installation parameters. This may lead to unsupported configurations from the perspective of Docker or from the perspective of your own organization’s guidelines and standards.
  • 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, but instead installs the latest version released in the edge channel.
  • Do not use the convenience script if you have already installed Docker on the host using another mechanism.

This example uses the script on get.docker.com to install the latest version of Docker Engine-Community on Linux. to install the latest test version, use test.docker.com instead. in each of the following commands, replace get with test each time it appears.

$ 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 using something like

$ sudo usermod -aG docker your-user

Uninstall docker

Delete the installation package:

sudo apt-get purge docker-ce

Deleting images, containers, configuration files, etc:

sudo rm -rf /var/lib/docker
Like(0)