For the interpretation of Docker installed on Ubuntu, ali Cloud test machine is used

Install Docker Engine on Ubuntu

Estimated reading time: 11 minutes

Estimated reading time: 11 minutes

To get started with Docker Engine on Ubuntu, make sure you meet the prerequisites, then install Docker.

Start Docker Engine in Ubuntu and make sure the following requirements are met before installing Docker

Prerequisites (prepare)

Operating System Requirements

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions.

  • Ubuntu 21.04 Hirsute
  • Ubuntu Groovy 20.10
  • Ubuntu 20.04 (LTS) Focal
  • Ubuntu 18.04 (LTS) Bionic
  • Ubuntu 16.04 (LTS) Xenial

Docker Engine is supported on x86_64 (or amd64), armhf, and arm64 architectures.

Uninstall old version

Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them:

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

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

It’s OK if apt-get reports that none of these packages are installed.

If apt-get reports that no packages have been installed, it’s ok

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. If you do not need to save your existing data, and want to start with a clean installation, refer to the uninstall Docker Engine section at the bottom of this page.

In the /var/lib/docker-/ folder, images, containers, volumes, and networks are retained. If you don’t need to keep existing data and want to start using the cleanest version, see uninstall Docker Engine at the bottom of the page

Supported Storage Drivers

Docker Engine on Ubuntu supports overlay2, aufs and btrfs storage drivers.

Docker supports overlay2, Aufs and BTRFS storage drivers in Ubuntu

Docker Engine uses the overlay2 storage driver by default. If you need to use aufs instead, you need to configure it manually. See use the AUFS storage driver

Docker uses the Overlay2 storage engine by default. If you want to use the AUFS engine, you need to configure it manually. Use the AUFS storage driver

Installation Methods

You can install Docker Engine in different ways, depending on your needs:

You can install Docker Engine in different ways, depending on yourself

  • Most users Set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.
    • Docker’s Repositories, the installation of the greatest number of users, is a repository for easy installation and upgrade work. Is the most recommended way
  • Some users download the DEB package and install it manually and manage upgrades completely manually. This is useful in situations such as installing Docker on air-gapped systems with no access to the internet.
    • Some people download the DEB package and install it manually, and then manage the upgrade completely manually. This is a very useful way to deal with such scenarios — installing Docker on a system without a network
  • In testing and development environments, some users choose to use automated convenience scripts to install Docker.
    • In test and dev environments, some people simply use the convenience scripts to install Docker

Install using the repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

When installing Docker for the first time on a new machine, you first need to create a Docker Repository. Then, you can install and update Docker from this repository

Set up the repository

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:

    • Update apt index and install packages by allowing APT to use repository via HTTPS requests
    $ sudo apt-get update
    
    $sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release
    Copy the code
  2. Add Docker’s official GPG key:

    • Add Docker official GPG key
    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    Copy the code
  3. Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below.

    • We use the following command to set up a stable repository. Want to addnightlyortestFrom the warehouse, in this onestableAdd after the wordnightlyortestIn the following command.

    Note: The lsb_release -cs sub-command below returns the name of your Ubuntu distribution, such as xenial. Sometimes, in a distribution like Linux Mint, you might need to change $(lsb_release -cs) to your parent Ubuntu distribution. For example, if you are using Linux Mint Tessa, you could use bionic. Docker does not offer any guarantees on untested and unsupported Ubuntu distributions.

    • x86_64 / amd64
    • armhf
    • arm64
    $ echo \
      "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    Copy the code

Install Docker EngineThe core)

  1. Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

    • Update apt package index, installThe latestVersion of the Docker engine or install a special version of the Docker engine in Step 2
     $ sudo apt-get update
     $ sudo apt-get install docker-ce docker-ce-cli containerd.io
    Copy the code

    Got multiple Docker repositories?

    Get multiple Docker repositories

    If you have multiple Docker repositories enabled, installing or updating without specifying a version in the apt-get install or apt-get update command always installs the highest possible version, which may not be appropriate for your stability needs.

    If you have more than one Docker engine, install and upgrade non-specified versions of the Docker engine using apt-get install or apt-get update command always install the latest version for us. That may not suit our needs.

  2. To install a specific version of Docker Engine, list the available versions in the repo, then select and install:

    • To install a specified version of Docker, list all available versions in the repository, and then select install

    a. List the versions available in your repo:

    • Lists all available versions in the repository
    $ apt-cache madison docker-ceDocker - ce | easier. 09.1 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages Docker - ce | easier. 09.0 ~ 3-0 ~ ubuntu - xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages Docker - ce | 18.06.1 ~ ce ~ 3-0 ~ ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker - ce | 18.06.0 ~ ce ~ 3-0 ~ ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 PackagesCopy the code

    B. Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ Ubuntu-Xenial

    • Install a specified version using the second column in the version string, for example:So. 09.1 ~ 3-0 ~ ubuntu - xenial
    $ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
    Copy the code
  3. Verify that Docker Engine is installed correctly by running the hello-world image.

    • Verify that Docker is properly installed by running the Hello-world image
    $ sudo docker run hello-world
    Copy the code

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

    This command downloads a test image and runs it into a container. When the container runs, it prints out a message and leaves

Docker Engine is installed and running. The docker group is created but no users are added to it. You need to use sudo to run Docker commands. Continue to Linux postinstall to allow non-privileged users to run Docker commands and for other optional configuration steps.

The Docker engine is installed and running. The “Docker” group was created, but no users were added to it. You need to use “sudo” to run the Docker command. Continue Linux Postinstall allows non-privileged users to run Docker commands and other optional configuration steps.

Upgrade Docker Engine

To upgrade Docker Engine, first run sudo apt-get update, then follow the installation instructions, choosing the new version you want to install.

To update docker engine, first need to run sudo apt-get update, then we need to operate the above installation steps in the installation, select the latest version to install

Install from a package(deb)

If you cannot use Docker’s 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.

If you can’t use the Docker repository to install the Docker engine, you can download the.deb version file you want and install it manually. When you want to update Docker you need to download a new file every time

  1. Go to https://download.docker.com/linux/ubuntu/dists/, choose your Ubuntu version, then browse to pool/stable/, choose amd64, armhf, or arm64, and download the .deb file for the Docker Engine version you want to install.

    • Go to this websitehttps://download.docker.com/linux/ubuntu/dists/, select your Ubuntu version and let browse laterpool/stable/, the choice ofamd64.armhf, or arm64Then download the version you want to install.debfile

    Note: To install a nightly or test (pre-release) package, change the word stable in the above URL to nightly or test. Learn about nightly and test channels.

  2. Install Docker Engine, changing the path below to the path where you downloaded the Docker package.

    • Select the path where the docker package is located and use DPKG to install the Docker
    $ sudo dpkg -i /path/to/package.deb
    Copy the code

    The Docker daemon starts automatically.

    The Docker daemon starts automatically.

  3. Verify that Docker Engine is installed correctly by running the hello-world image.

    • Verify that Docker is properly installed by running the Hello-world image
    $ sudo docker run hello-world
    Copy the code

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

    This command downloads a test image and runs it into a container. When the container runs, it prints out a message and leaves

Docker Engine is installed and running. The docker group is created but no users are added to it. You need to use sudo to run Docker commands. Continue to Post-installation steps for Linux to allow non-privileged users to run Docker commands and for other optional configuration steps.

The Docker engine is installed and running. The “Docker” group was created, but no users were added to it. You need to use “sudo” to run the Docker command. Continue Linux Postinstall allows non-privileged users to run Docker commands and other optional configuration steps.

Upgrade Docker Engine

To upgrade Docker Engine, download the newer package file and repeat the installation procedure, pointing to the new file.

To update the Docker engine, download the latest package file and repeat the installation process, pointing to our new file

Install using the convenience script

Docker provides a convenience script at get.docker.com to install Docker into development environments quickly and non-interactively. The convenience script is not recommended for production environments, but can be used as an example to create a provisioning script that is tailored to your needs. Also refer to the install using the repository steps to learn about installation steps to install using the package repository. The source code for the script is open source, and can be found in the docker-install repository on GitHub.

Docker provides a convenient script at get.docker.com to install Docker into the development environment quickly and non-interactively. This handy script is not recommended in a production environment, but it can be used as a use case to create a new script tailored to your needs. Learn about the installation steps in using package by using the Docker repository steps described above. The source code for this script is open source and can be found in docker-install repository on GitHub.

Always examine scripts downloaded from the internet before running them locally. Before installing, make yourself familiar with potential risks and limitations of the convenience script:

Always check scripts downloaded from the Internet before running them locally. Before installation, familiarize yourself with the potential risks and limitations of convenient scripts:

  • The script requires root or sudo privileges to run.
    • The script requires root or sudo permission to run.
  • The script attempts to detect your Linux distribution and version and configure your package management system for you, and does not allow you to customize most installation parameters.
    • This script attempts to detect your Linux distribution and version and configure the package management system for you, but does not allow you to customize most installation parameters.
  • The script installs dependencies and recommendations without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.
    • Scripts install dependencies and recommendations without requiring validation. Depending on the current configuration of the host, this may involve installing a large number of packages.
  • By default, the script installs the latest stable release of Docker, containerd, and runc. When using this script to provision a machine, this may result in unexpected major version upgrades of Docker. Always test (major) upgrades in a test environment before deploying to your production systems.
    • By default, this script installs the latest stable versions of Docker, Containerd, and Runc. When using this script to configure your computer, this can cause an unexpected upgrade to the major version of Docker. Always test (major) upgrades in a test environment before deploying to a production system.
  • The script is not designed to upgrade an existing Docker installation. When using the script to update an existing installation, dependencies may not be updated to the expected version, causing outdated versions to be used.
    • This script is not designed to upgrade an existing Docker installation. When scripts are used to update an existing installation, dependencies may not be updated to the expected version, resulting in expired versions being used.

Tip: preview script steps before running

View the script before running

You can run the script with the DRY_RUN=1 option to learn what steps the script will execute during installation:

You can run the script and set DRY_RUN=1 to know when the script executes the installation

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ DRY_RUN=1 sh ./get-docker.sh
Copy the code

This example downloads the script from get.docker.com and runs it to install the latest stable release of Docker on Linux:

This example shows downloading the script from get.docker.com and running it to install the latest version of Docker on a Linux machine

$ curl -fsSL https://get.docker.com -o get-docker.sh $ sudo sh get-docker.sh Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737 <... >Copy the code

Docker is installed. The docker service starts automatically on Debian based distributions. On RPM based distributions, such as CentOS or Fedora, you need to start it manually using the appropriate systemctl or service command. As the message indicates, non-root users cannot run Docker commands by default.

Docker has been installed. Docker services start automatically on debian-based distributions. On RPm-based distributions, such as CentOS or Fedora, you need to manually start it with the appropriate systemctl or service command. As the message shows, non-root users cannot run Docker commands by default.

Use Docker as a non-privileged user, or install in rootless mode?

The installation script requires root or sudo privileges to install and use Docker. If you want to grant non-root users access to Docker, refer to the post-installation steps for Linux. Docker can also be installed without root privileges, or configured to run in rootless mode. For instructions on running Docker in rootless mode, refer to run the Docker daemon as a non-root user (rootless mode).

Install pre-releases

Docker also provides a convenience script at test.docker.com to install pre-releases of Docker on Linux. This script is equivalent to the script at get.docker.com, But configures your package manager to enable the “test” channel from our package repository, which includes both stable and pre-releases (beta versions, release-candidates) of Docker. Use this script to get early access to new releases, And to evaluate them in a testing environment before they are released as stable.

To install the latest version of Docker on Linux from the “test” channel, run:

$ curl -fsSL https://test.docker.com -o test-docker.sh $ sudo sh test-docker.sh <... >Copy the code

Upgrade Docker after using the convenience script

If you installed Docker using the convenience script, you should upgrade Docker using your package manager directly. There is no advantage to re-running the convenience script, and it can cause issues if it attempts to re-add repositories which have already been added to the host machine.

If docker is installed using scripts, you should directly upgrade your Docker using your package management tool. There is no use in re-running the script, if you try to add the library to your host it will cause problems

Uninstall Docker Engine Uninstall Docker Engine

  1. Uninstall the Docker Engine, CLI, and Containerd packages:

    • Uninstall the Docker engine, client, and related packages
    $ sudo apt-get purge docker-ce docker-ce-cli containerd.io
    Copy the code
  2. Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

    • Images, containers, volumes, or custom configuration files are not automatically removed from your host. Delete all mirrors, containers, and volumes
    $ sudo rm -rf /var/lib/docker
    $ sudo rm -rf /var/lib/containerd
    Copy the code

You must delete any edited configuration files manually.

You must manually delete any configuration files that have been edited