Docker 的安装 【Debian 为例】

参考地址

https://docs.docker.com/install/linux/docker-ce

系统要求

操作系统要求

你需要64位的 Debian 或者 Raspbian 版本:

  • Buster 10
  • Stretch 9 (stable) / Raspbian Stretch

支持的架构 x86_64 (或者 amd64), armhf, 和 arm64` .

卸载以前的版本

docker以前的版本被称为 docker, docker.io , or docker-engine`.

如果你安装过,请卸载它们,运行以下命令

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

提示ok 或者 apt-get 提示 none of these packages are installed 都说明已经卸载完成

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. The Docker CE package is now called docker-ce.

安装 Docker CE

三种不同安装docker CE 的方式

  • 通常可以设置Docker的仓库地址 ) 来安装。推荐这种方式,如果你是Raspbian,那么不推荐,请看下面的。
  • 通过deb报手动安装和管理,通常用于没有网络连接的时候
  • 测试环境下通常使用脚本来安装convenience scripts .当前仅仅支持 approach for Raspbian.

通过仓库源安装

在你第一次在新的机器上安装docker的时候,需要设置docker安装源地址。

Raspbian 用户不能使用这个方法!

对于 Raspbian, 现在还没有支持通过源安装. 请使用下面的脚本安装方法 convenience script.

设置软件仓库

  1. 更新 apt 包的目录:

    $ sudo apt-get update
  2. 安装软件以允许apt 使用https安装源:

    $ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg2 \
    software-properties-common
  3. 增加 Docker’s 官方的 GPG key:

    $ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

使用这个指纹验证一下这个key9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88`, 通过搜索指纹的最后8个字符.

$ sudo apt-key fingerprint 0EBFCD88

pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) 
sub   4096R/F273FCD8 2017-02-22
  1. 通过下面的命令设置stable 仓库,stable 也就是稳定版的意思,和release差不多的意思,区别于 dev 等等. 如果想要增加 nightly 或者 test 仓库, 那就在下面的命令行的stable 后面增加 nightly 或者 test (或者都加上) 。 了解 nightlytest 频道.

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

  • x86_64 / amd64
  • armhf
  • arm64

    $ sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/debian \
       $(lsb_release -cs) \
       stable"

安装Docker CE

Note: This procedure works for Debian on x86_64 / amd64, Debian ARM, or Raspbian.

  1. 更新 apt 包索引.

    $ sudo apt-get update
  2. 安装 最新版本 Docker CE 和容器, 或者依照下一步安装特定版本的Docker:

    $ sudo apt-get install docker-ce docker-ce-cli containerd.io

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

  1. 想要安装一个 特定版本 的 Docker CE, 首先列出repo中所有可选版本,然后选择并安装一个

    1. 列出你repo中的版本:
    $ apt-cache madison docker-ce
    
      docker-ce | 5:18.09.1~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
      docker-ce | 5:18.09.0~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
      docker-ce | 18.06.1~ce~3-0~debian        | https://download.docker.com/linux/debian stretch/stable amd64 Packages
      docker-ce | 18.06.0~ce~3-0~debian        | https://download.docker.com/linux/debian stretch/stable amd64 Packages
      ...
    1. 使用第二列中的版本字符串来安装某一个特定的版本, 举个例子,如果要安装, 5:18.09.1~3-0~debian-stretch .
    $ sudo apt-get install docker-ce= docker-ce-cli= containerd.io
  2. 通过运行 hello-world 镜像来确认一下Docker CE已经正确的安装在你的计算机中.

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

如果提示 service not started 之类的,请先运行

sudo service docker start 
或者
sudo systemctl start docker

Docker CE 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

首先运行 sudo apt-get update, 然后根据 上面的安装指南, 选择一个新的版本安装即可

通过软件包安装

If you cannot use Docker’s repository to install Docker CE, 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.

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

Note: To install a nightly package, change the word stable in the URL to nightly. Learn about nightly and test channels.

  1. Install Docker CE, changing the path below to the path where you downloaded the Docker package.

    $ sudo dpkg -i /path/to/package.deb

The Docker daemon starts automatically.

  1. Verify that Docker CE is installed correctly by running the hello-world image.

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

下载更新版本的软件包然后重复 安装指南, 部署新的安装包.

Install using the convenience script

Docker provides convenience scripts at get.docker.com and test.docker.com for installing edge and testing versions of Docker CE into development environments quickly and non-interactively. The source code for the scripts is in the docker-install repository. Using these scripts is not recommended for production environments, and you should understand the potential risks before you use them:

  • The scripts require root or sudo privileges to run. Therefore, you should carefully examine and audit the scripts before running them.
  • The scripts attempt to detect your Linux distribution and version and configure your package management system for you. In addition, the scripts do not allow you to customize any installation parameters. This may lead to an unsupported configuration, either from Docker’s point of view or from your own organization’s guidelines and standards.
  • The scripts install all dependencies and recommendations of the package manager without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.
  • The script does not provide options to specify which version of Docker to install, and installs the latest version that is released in the “edge” channel.
  • Do not use the convenience script if Docker has already been installed on the host machine using another mechanism.

This example uses the script at get.docker.com to install the latest release of Docker CE on Linux. To install the latest testing version, use test.docker.com instead. In each of the commands below, replace each occurrence of get with test.

Warning:

Always examine scripts downloaded from the internet before running them locally.

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

If you would like to use Docker as a non-root user, you should now consider adding your user to the “docker” group with something like:

  sudo usermod -aG docker your-user

Remember to log out and back in for this to take effect!

Warning:

Adding a user to the “docker” group grants them the ability to run containers which can be used to obtain root privileges on the Docker host. Refer to Docker Daemon Attack Surface for more information.

Docker CE is installed. It starts automatically on DEB-based distributions. On RPM-based distributions, you need to start it manually using the appropriate systemctl or servicecommand. As the message indicates, non-root users can’t run Docker commands by default.

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.

卸载Docker

  1. Uninstall the Docker CE package:

    $ sudo apt-get purge docker-ce
  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

You must delete any edited configuration files manually.

下一步

requirements, apt, installation, debian, install, uninstall, upgrade, [update](

上一篇
下一篇