Debian 9 安装 Docker CE

技术教程 风为裳 4浏览 0评论 繁體

简介

Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的、可移植的、自给自足的容器。开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括VMs(虚拟机)、bare metal、OpenStack集群和其他的基础应用平台。

本指南将帮助您在Debian 9 Stretch上安装Docker。 本指南也适用于以前的版本,即Debian 8(Jessie)
注意:Docker需要64位版本的Debian OS,内核版本应至少为3.10

Docker现在有两个版本。

  • 社区版(CE)
  • 企业版(EE)

在这里,我们将从Docker存储库安装Docker Comunity Edition(CE)。

安装之前

卸载旧版本的Docker,称为“docker”或“docker-engine”以及相关的依赖项。 如果您的系统没有Docker软件包,请跳过以下步骤。

sudo apt-get -y remove docker docker-engine docker.io

保留/var/lib/docker/目录下的卷,图像和网络等内容。

设置Docker存储库

安装以下软件包以使“apt”获得https方法的支持。

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates wget software-properties-common

在系统上添加Docker存储库的GPG密钥。

wget https://download.docker.com/linux/debian/gpg
sudo apt-key add gpg

通过在终端中运行以下命令将官方Docker存储库添加到系统。

echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee -a /etc/apt/sources.list.d/docker.list
sudo apt-get update

查询docker储存库详细信息

[[email protected]]:# sudo apt-cache policy docker-ce

docker-ce:
  Installed: 18.06.1~ce~3-0~debian
  Candidate: 18.06.1~ce~3-0~debian
  Version table:
 *** 18.06.1~ce~3-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
        100 /var/lib/dpkg/status
     18.06.0~ce~3-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     18.03.1~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     18.03.0~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.12.1~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.12.0~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.09.1~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.09.0~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.06.2~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.06.1~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.06.0~ce-0~debian 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.3~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.2~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.1~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages
     17.03.0~ce-0~debian-stretch 500
        500 https://download.docker.com/linux/debian stretch/stable amd64 Packages

安装Docker

sudo apt-get -y install docker-ce

控制Docker服务命令

sudo systemctl start docker     //运行

sudo systemctl stop docker      //停止

sudo systemctl restart docker   //重启

sudo systemctl status docker    //状态

sudo systemctl enable docker    //设置开机自启动

验证Docker是否安装成功

[[email protected]]:# sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
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/

官方提供的一键安装Docker命令。Docker仅支持Linux内核3.10以上版本。支持Centos7,ubuntu14,fedora26,raspbian-jessie及以上版本

wget -qO- get.docker.com | bash

 

转载请注明:风为裳 » Debian 9 安装 Docker CE

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址