Docker在Ubuntu上的安装(官方翻译)

针对于docker在Ubuntu上安装的解读,使用的是阿里云测试机

Install Docker Engine on Ubuntu

Estimated reading time: 11 minutes

大概评估阅读用时:11分钟

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

开始Docker Engine 在 Ubuntu,确保满足以下的需求,然后再安装docker

Prerequisites(准备)

OS requirements(系统要求)

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:(版本:注意64位)

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

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:

老版本的Docker被叫做docker, docker.io, or docker-engine,如果他们被安装了,请先卸载他们

$ sudo apt-get remove docker docker-engine docker.io containerd runc
复制代码

image.png

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

如果 apt-get 报告了这里已经没有任何的包被安装了,那就妥了

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.

/var/lib/docker/文件夹下,包含images镜像, containers容器, volumes卷, and networks网络,被保留。如果你不需要保留存在的数据,想要开始使用一个最干净的版本,就去看在网页最下面的卸载方式 uninstall Docker Engine

Supported storage drivers(支持的存储驱动程序)

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

Docker 在Ubuntu 支持 overlay2, aufs and btrfs 存储驱动

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 默认使用 overlay2存储引擎。如果你想使用 aufs 引擎,你需要进行手动配置。看这个链接use the AUFS storage driver

Installation methods(安装方式)

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

你可以使用不同的方式进行Docker Engine的安装,取决于你自己

  • 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,非常简单的完成安装和升级工作。是最被推荐的方式
  • 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.
    • 有些人下载DEB安装包并且手动的安装,然后管理升级也是完全的手动的方式。这是一个非常有用的方式应对这样的场景–安装Docker在一个没有网络的系统中
  • In testing and development environments, some users choose to use automated convenience scripts to install Docker.
    • 在test和dev环境中,一些人直接使用convenience scripts<便捷脚本>进行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.

在一个新机器上第一次安装Docker的时候,你首先需要建立Docker repository,然后,你能安装和更新Docker从这个仓库中

Set up the repository(亲测成功)

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

    • 更新apt包的索引 并且 安装packages 通过允许apt 去使用repository通过https请求的方式
    $ sudo apt-get update
    
    $ sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        gnupg \
        lsb-release
    复制代码
  2. Add Docker’s official GPG key:

    • 添加Docker官方的GPG key
    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    复制代码
  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.

    • 我们使用以下的命令去建立一个稳定版的仓库。想要添加nightly 或者 test 仓库的, 在这个stable词的后面添加上nightly 或者 test在下面的命令中。

    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
    复制代码

Install Docker Engine(安装docker引擎核心)

  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:

    • 更新apt的包的索引,安装最新版本的Docker引擎 或者在2步中安装一个特殊版本的Docker引擎
     $ sudo apt-get update
     $ sudo apt-get install docker-ce docker-ce-cli containerd.io
    复制代码

    Got multiple Docker repositories?

    获取多个Docker仓库

    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.

    如果你有多个Docker引擎,安装和升级非指定版本在使用 apt-get install or apt-get update 命令总是给我们安装最新的版本。那可能不适合我们的需要。

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

    • 去安装一个指定的版本Docker,列出所有的可以获得版本在仓库中,然后选择进行安装

    a. List the versions available in your repo:

    • 列出仓库中的所有可用的版本
    $ apt-cache madison docker-ce
    
      docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
      docker-ce | 5:18.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 Packages
    复制代码

    b. Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial.

    • 安装一个指定的版本使用版本字符串中的第二列,例如:5:18.09.1~3-0~ubuntu-xenial
    $ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
    复制代码
  3. Verify that Docker Engine is installed correctly by running the hello-world image.

    • 验证docker是不是正确的安装通过运行hello-world镜像
    $ sudo docker run hello-world
    复制代码

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

    这个命令下载一个测试镜像并且运行他进入一个容器。当容器运行的时候,他将打印出一条信息并且离开

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.

Docker引擎已安装并运行。“docker”组已创建,但未向其中添加任何用户。您需要使用“sudo”来运行Docker命令。继续Linux postinstall允许非特权用户运行Docker命令和其他可选配置步骤。

Upgrade Docker Engine(更新docker)

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

更新docker引擎,首先需要运行sudo apt-get update,然后我们在安装上面的安装步骤在操作一遍就行了,选择最新的版本进行安装

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.

如果不能使用docker仓库去安装Docker引擎,你可以下载 .deb 你想要版本文件然后手动安装他。当你想要更新Docker的时候每次你都需要去下载一个新文件

  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.

    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.

    • 选择这个路径你下在docker包的位置,使用dpkg进行docker的安装
    $ sudo dpkg -i /path/to/package.deb
    复制代码

    The Docker daemon starts automatically.

    Docker守护进程自动启动。

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

    • 验证docker是不是正确的安装通过运行hello-world镜像
    $ sudo docker run hello-world
    复制代码

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

    这个命令下载一个测试镜像并且运行他进入一个容器。当容器运行的时候,他将打印出一条信息并且离开

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.

Docker引擎已安装并运行。“docker”组已创建,但未向其中添加任何用户。您需要使用“sudo”来运行Docker命令。继续Linux postinstall允许非特权用户运行Docker命令和其他可选配置步骤。

Upgrade Docker Engine(更新docker引擎)

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

为了更新docker引擎,下载这个最新package文件然后重复安装过程、指向我们的新文件

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提供一个方便的脚本在 get.docker.com 去安装docker进入开发环境快速且非交互式的。这个方便的脚本不被推荐在生产环境中,但是它可以被当作一个用例去创建一个新脚本根据您的需要量身定制。根据前面提到的安装通过使用docker仓库的步骤去学习关于安装步骤在使用package .这个源码对于这个脚本是开源的,能够发现在 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:

在本地运行之前,请始终检查从internet下载的脚本。安装前,请熟悉便利脚本的潜在风险和限制:

  • The script requires root or sudo privileges to run.
    • 脚本需要“root”或“sudo”权限才能运行。
  • 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.
    • 该脚本尝试检测您的Linux发行版和版本,并为您配置包管理系统,但不允许您自定义大多数安装参数。
  • 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.
    • 脚本安装依赖项和建议,而不要求确认。这可能会安装大量软件包,具体取决于主机的当前配置。
  • 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.
    • 默认情况下,该脚本安装Docker、containerd和runc的最新稳定版本。使用此脚本配置计算机时,这可能会导致Docker的主要版本意外升级。在部署到生产系统之前,请始终在测试环境中测试(主要)升级。
  • 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.
    • 该脚本不是为升级现有Docker安装而设计的。使用脚本更新现有安装时,依赖项可能无法更新到预期版本,从而导致使用过期版本。

Tip: preview script steps before running

在运行前查看脚本

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

你能够运行这个脚本设置参数 DRY_RUN=1去知道脚本在执行安装的时候执行到那步了

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ DRY_RUN=1 sh ./get-docker.sh
复制代码

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

这个例子展示下载这个脚本从get.docker.com并且运行他去安装最新的版本的Docker在linux机器上

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
Executing docker install script, commit: 7cae5f8b0decc17d6571f9f52eb840fbc13b2737
<...>
复制代码

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。docker服务在基于Debian的分发版上自动启动。在基于RPM的发行版上,例如CentOS或Fedora,您需要使用适当的systemctl或service命令手动启动它。正如消息所示,非根用户默认无法运行Docker命令。

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
<...>
复制代码

Upgrade Docker after using the convenience script(使用脚本安装docker后的升级)

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.

如果安装了docker使用脚本的方式,你应该直接升级你的docker使用你的包管理工具。这里没有任何的用去重新运行这个脚本,如果你企图去添加这个库在你的主机上已经添加过的时候他就会出现问题

Uninstall Docker Engine(完全卸载docker并删除数据)

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

    • 卸载docker的引擎、客户端和相关的包
    $ sudo apt-get purge docker-ce docker-ce-cli containerd.io
    复制代码
  2. Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

    • 镜像、容器、卷、或者自定义的配置文件在你的主机上不会自动移除。删除所有的镜像、容器、和卷
    $ sudo rm -rf /var/lib/docker
    $ sudo rm -rf /var/lib/containerd
    复制代码

You must delete any edited configuration files manually.

你必须手动删除任何编辑过的配置文件

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享