logo头像
Snippet 博客主题

Deepin Linux安装Docker

普通安装

一般的Linux(Debian、Unbantu)发行版可以执行以下命令进行安装:

1
wget -qO- https://get.docker.com/ | sh

但是在Deepin执行这命令会安装失败。

查阅资料可以找到docker支持的Linux发行版。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
x86_64-centos-7
x86_64-fedora-28
x86_64-fedora-29
x86_64-debian-jessie
x86_64-debian-stretch
x86_64-debian-buster
x86_64-ubuntu-trusty
x86_64-ubuntu-xenial
x86_64-ubuntu-bionic
x86_64-ubuntu-cosmic
s390x-ubuntu-xenial
s390x-ubuntu-bionic
s390x-ubuntu-cosmic
ppc64le-ubuntu-xenial
ppc64le-ubuntu-bionic
ppc64le-ubuntu-cosmic
aarch64-ubuntu-xenial
aarch64-ubuntu-bionic
aarch64-ubuntu-cosmic
aarch64-debian-jessie
aarch64-debian-stretch
aarch64-debian-buster
aarch64-fedora-28
aarch64-fedora-29
aarch64-centos-7
armv6l-raspbian-jessie
armv7l-raspbian-jessie
armv6l-raspbian-stretch
armv7l-raspbian-stretch
armv7l-debian-jessie
armv7l-debian-stretch
armv7l-debian-buster
armv7l-ubuntu-trusty
armv7l-ubuntu-xenial
armv7l-ubuntu-bionic
armv7l-ubuntu-cosmic

查看了我的系统的版本:

1
2
3
4
5
6
litong@LT:~$ cat /etc/issue
Deepin GNU/Linux 15.10.2 \n \l
litong@LT:~$ cat /etc/debian_version
9.0
litong@LT:~$ uname -r
4.15.0-29deepin-generic

这里我的系统是Deepin 15.10.2,而我的Deepin Linux是基于Debian 9.0,即上述的版本x86_64-debian-stretch进行的深度开发,我系统Debian 9.0是sid版的,并不是release版本,所以不是docker官方认证的stable版本,故不支持Deepin Linux。

Deepin上安装Docker

  1. 若以前安装过旧版本则先卸载旧版本,如没有安装过,则跳过;

    1
    sudo apt-get remove docker.io docker-engine
  2. 安装docker-ce与密钥管理与下载相关依赖工具;

    1
    sudo apt-get install apt-transport-https ca-certificates curl python-software-properties software-properties-common
  3. 下载并安装密匙并验证秘钥,若成功则返回OK;

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

    如果不成功(docker官方在墙外,需科学上网),则使用国内镜像源将上述命令换成

    1
    curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -
  4. 验证秘钥是否安装成功;

    1
    2
    3
    4
    5
    6
    litong@LT:~$ sudo apt-key fingerprint 0EBFCD88
    [sudo] litong 的密码:
    pub rsa4096 2017-02-22 [SCEA]
    9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
    uid [ 未知 ] Docker Release (CE deb) <docker@docker.com>
    sub rsa4096 2017-02-22 [S]
  5. 安装docker-ce组件;

    1
    sudo apt-get install docker-ce
  6. 测试是否安装成功;

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    litong@LT:~$ docker version
    Client: Docker Engine - Community
    Version: 19.03.2
    API version: 1.40
    Go version: go1.12.8
    Git commit: 6a30dfca03
    Built: Thu Aug 29 05:29:49 2019
    OS/Arch: linux/amd64
    Experimental: false
    Server: Docker Engine - Community
    Engine:
    Version: 19.03.2
    API version: 1.40 (minimum version 1.12)
    Go version: go1.12.8
    Git commit: 6a30dfca03
    Built: Thu Aug 29 05:28:23 2019
    OS/Arch: linux/amd64
    Experimental: false
    containerd:
    Version: 1.2.6
    GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
    runc:
    Version: 1.0.0-rc8
    GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f
    docker-init:
    Version: 0.18.0
    GitCommit: fec3683
  1. 普通用户运行docker

    安装docker完成后,普通用户执行docker命令时候,有可能会出现错误提示:

    1
    Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/json: dial unix /var/run/docker.sock: connect: permission denied

    通过查阅资料,在docker mannual找到解决思路:

    Manage Docker as a non-root user
    The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user.
    If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

    大概翻译了一下,意思是:ocker进程使用Unix Socket而不是TCP端口。而默认情况下,Unix socket属于root用户,需要root权限才能访问。

    解决方案:

    docker守护进程启动的时候,会默认赋予名字为docker的用户组读写Unix socket的权限,因此只要创建docker用户组,并将当前用户加入到docker用户组中,那么当前用户就有权限访问Unix socket了,进而也就可以执行docker相关命令。

    1. 添加docker用户组,若已由docker组则跳过;

      1
      sudo groupadd docker
    2. 将登陆用户加入到docker用户组中;

      1
      sudo gpasswd -a $USER docker
    3. 更新用户组;

      1
      newgrp docker
    4. 测试docker命令是否可以使用sudo正常使用。

      1
      docker ps
  1. 使用阿里云docker镜像加速

    1. 进入阿里云控制台,选择容器镜像服务,左边菜单最下方的镜像中心-镜像加速器;

    2. 根据阿里云操作文档选择不同系统的镜像加速命令;

      1
      2
      3
      4
      5
      6
      7
      8
      sudo mkdir -p /etc/docker
      sudo tee /etc/docker/daemon.json <<-'EOF'
      {
      "registry-mirrors": ["替换你的加速器地址"]
      }
      EOF
      sudo systemctl daemon-reload
      sudo systemctl restart docker
支付宝打赏 微信打赏

请作者喝杯咖啡吧