#安装以下包以使apt可以通过HTTPS使用存储库(repository): $ sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common #添加Docker官方的GPG密钥: $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - #使用下面的命令来设置stable存储库: $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" #再更新一下apt包索引: $ sudo apt-get update #安装最新版本的Docker CE: $ sudo apt-get install -y docker-ce
安装实例
官网安装教程:https://docs.docker.com/install/linux/docker-ce/ubuntu/
root@iZwz9fvt1y9kp07r5zpun6Z:~# docker -v Docker version 1.13.1, build 092cba3 root@iZwz9fvt1y9kp07r5zpun6Z:~# sudo apt-get remove docker docker-engine docker.io sudo: unable to resolve host iZwz9fvt1y9kp07r5zpun6Z Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package docker-engine root@iZwz9fvt1y9kp07r5zpun6Z:~# sudo apt-get update sudo: unable to resolve host iZwz9fvt1y9kp07r5zpun6Z Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease Reading package lists... Done root@iZwz9fvt1y9kp07r5zpun6Z:~# sudo apt-get install \ > apt-transport-https \ > ca-certificates \ > curl \ > software-properties-common sudo: unable to resolve host iZwz9fvt1y9kp07r5zpun6Z Reading package lists... Done Building dependency tree Reading state information... Done ca-certificates is already the newest version (20170717~16.04.1). The following packages were automatically installed and are no longer required: linux-headers-4.4.0-62 linux-headers-4.4.0-62-generic linux-headers-4.4.0-93 linux-headers-4.4.0-93-generic linux-image-4.4.0-62-generic linux-image-4.4.0-93-generic linux-image-extra-4.4.0-62-generic linux-image-extra-4.4.0-93-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libcurl3-gnutls python3-pycurl python3-software-properties unattended-upgrades Suggested packages: libcurl4-gnutls-dev python-pycurl-doc python3-pycurl-dbg bsd-mailx The following NEW packages will be installed: python3-pycurl python3-software-properties software-properties-common unattended-upgrades The following packages will be upgraded: apt-transport-https curl libcurl3-gnutls 3 upgraded, 4 newly installed, 0 to remove and 122 not upgraded. Need to get 453 kB of archives. After this operation, 799 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 curl amd64 7.47.0-1ubuntu2.9 [138 kB] Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 libcurl3-gnutls amd64 7.47.0-1ubuntu2.9 [184 kB] Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 apt-transport-https amd64 1.2.27 [26.1 kB] Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/main amd64 python3-pycurl amd64 7.43.0-1ubuntu1 [42.3 kB] Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 python3-software-properties all 0.96.20.7 [20.3 kB] Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 software-properties-common all 0.96.20.7 [9,452 B] Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 unattended-upgrades all 0.90ubuntu0.9 [32.3 kB] Fetched 453 kB in 0s (3,452 kB/s) Preconfiguring packages ... (Reading database ... 166259 files and directories currently installed.) Preparing to unpack .../curl_7.47.0-1ubuntu2.9_amd64.deb ... Unpacking curl (7.47.0-1ubuntu2.9) over (7.47.0-1ubuntu2.7) ... Preparing to unpack .../libcurl3-gnutls_7.47.0-1ubuntu2.9_amd64.deb ... Unpacking libcurl3-gnutls:amd64 (7.47.0-1ubuntu2.9) over (7.47.0-1ubuntu2.7) ... Preparing to unpack .../apt-transport-https_1.2.27_amd64.deb ... Unpacking apt-transport-https (1.2.27) over (1.2.26) ... Selecting previously unselected package python3-pycurl. Preparing to unpack .../python3-pycurl_7.43.0-1ubuntu1_amd64.deb ... Unpacking python3-pycurl (7.43.0-1ubuntu1) ... Selecting previously unselected package python3-software-properties. Preparing to unpack .../python3-software-properties_0.96.20.7_all.deb ... Unpacking python3-software-properties (0.96.20.7) ... Selecting previously unselected package software-properties-common. Preparing to unpack .../software-properties-common_0.96.20.7_all.deb ... Unpacking software-properties-common (0.96.20.7) ... Selecting previously unselected package unattended-upgrades. Preparing to unpack .../unattended-upgrades_0.90ubuntu0.9_all.deb ... Unpacking unattended-upgrades (0.90ubuntu0.9) ... Processing triggers for man-db (2.7.5-1) ... Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for dbus (1.10.6-1ubuntu3.3) ... Processing triggers for systemd (229-4ubuntu21.2) ... Processing triggers for ureadahead (0.100.0-19) ... Setting up libcurl3-gnutls:amd64 (7.47.0-1ubuntu2.9) ... Setting up curl (7.47.0-1ubuntu2.9) ... Setting up apt-transport-https (1.2.27) ... Setting up python3-pycurl (7.43.0-1ubuntu1) ... Setting up python3-software-properties (0.96.20.7) ... Setting up software-properties-common (0.96.20.7) ... Setting up unattended-upgrades (0.90ubuntu0.9) ... Creating config file /etc/apt/apt.conf.d/50unattended-upgrades with new version insserv: can not symlink(../init.d/aegis, ../rc2.d/S02aegis): File exists insserv: can not symlink(../init.d/aegis, ../rc3.d/S02aegis): File exists insserv: can not symlink(../init.d/aegis, ../rc4.d/S02aegis): File exists insserv: can not symlink(../init.d/aegis, ../rc5.d/S02aegis): File exists Synchronizing state of unattended-upgrades.service with SysV init with /lib/systemd/systemd-sysv-install... Executing /lib/systemd/systemd-sysv-install enable unattended-upgrades Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for dbus (1.10.6-1ubuntu3.3) ... Processing triggers for systemd (229-4ubuntu21.2) ... Processing triggers for ureadahead (0.100.0-19) ... root@iZwz9fvt1y9kp07r5zpun6Z:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo: unable to resolve host iZwz9fvt1y9kp07r5zpun6Z OK root@iZwz9fvt1y9kp07r5zpun6Z:~# sudo apt-key fingerprint 0EBFCD88 sudo: unable to resolve host iZwz9fvt1y9kp07r5zpun6Z pub 4096R/0EBFCD88 2017-02-22 Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid Docker Release (CE deb) <docker@docker.com> sub 4096R/F273FCD8 2017-02-22 root@iZwz9fvt1y9kp07r5zpun6Z:~# sudo add-apt-repository \ > "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ > $(lsb_release -cs) \ > stable" sudo: unable to resolve host iZwz9fvt1y9kp07r5zpun6Z root@iZwz9fvt1y9kp07r5zpun6Z:~# sudo apt-get update sudo: unable to resolve host iZwz9fvt1y9kp07r5zpun6Z Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease Hit:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease Hit:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease Get:4 https://download.docker.com/linux/ubuntu xenial InRelease [66.2 kB] Get:5 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages [4,470 B] Fetched 70.7 kB in 1s (50.6 kB/s) Reading package lists... Done root@iZwz9fvt1y9kp07r5zpun6Z:~# apt-cache madison docker-ce 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 docker-ce | 18.03.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 18.03.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.12.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.12.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.06.2~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.06.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.06.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.3~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.2~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages root@iZwz9fvt1y9kp07r5zpun6Z:~# sudo apt-get install docker-ce=17.03.3~ce-0~ubuntu-xenial sudo: unable to resolve host iZwz9fvt1y9kp07r5zpun6Z Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: bridge-utils containerd dns-root-data dnsmasq-base libnetfilter-conntrack3 linux-headers-4.4.0-62 linux-headers-4.4.0-62-generic linux-headers-4.4.0-93 linux-headers-4.4.0-93-generic linux-image-4.4.0-62-generic linux-image-4.4.0-93-generic linux-image-extra-4.4.0-62-generic linux-image-extra-4.4.0-93-generic runc ubuntu-fan Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: aufs-tools libltdl7 The following packages will be REMOVED: docker.io The following NEW packages will be installed: aufs-tools docker-ce libltdl7 0 upgraded, 3 newly installed, 1 to remove and 121 not upgraded. Need to get 19.5 MB of archives. After this operation, 26.6 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/universe amd64 aufs-tools amd64 1:3.2+20130722-1.1ubuntu1 [92.9 kB] Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/main amd64 libltdl7 amd64 2.4.6-0.1 [38.3 kB] Get:3 https://download.docker.com/linux/ubuntu xenial/stable amd64 docker-ce amd64 17.03.3~ce-0~ubuntu-xenial [19.4 MB] Fetched 19.5 MB in 3s (6,058 kB/s) (Reading database ... 166317 files and directories currently installed.) Removing docker.io (1.13.1-0ubuntu1~16.04.2) ... '/usr/share/docker.io/contrib/nuke-graph-directory.sh' -> '/var/lib/docker/nuke-graph-directory.sh' Warning: Stopping docker.service, but it can still be activated by: docker.socket Processing triggers for man-db (2.7.5-1) ... Selecting previously unselected package aufs-tools. (Reading database ... 166224 files and directories currently installed.) Preparing to unpack .../aufs-tools_1%3a3.2+20130722-1.1ubuntu1_amd64.deb ... Unpacking aufs-tools (1:3.2+20130722-1.1ubuntu1) ... Selecting previously unselected package libltdl7:amd64. Preparing to unpack .../libltdl7_2.4.6-0.1_amd64.deb ... Unpacking libltdl7:amd64 (2.4.6-0.1) ... Selecting previously unselected package docker-ce. Preparing to unpack .../docker-ce_17.03.3~ce-0~ubuntu-xenial_amd64.deb ... Unpacking docker-ce (17.03.3~ce-0~ubuntu-xenial) ... Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for man-db (2.7.5-1) ... Processing triggers for systemd (229-4ubuntu21.2) ... Processing triggers for ureadahead (0.100.0-19) ... Setting up aufs-tools (1:3.2+20130722-1.1ubuntu1) ... Setting up libltdl7:amd64 (2.4.6-0.1) ... Setting up docker-ce (17.03.3~ce-0~ubuntu-xenial) ... Installing new version of config file /etc/default/docker ... Installing new version of config file /etc/init.d/docker ... Installing new version of config file /etc/init/docker.conf ... Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for systemd (229-4ubuntu21.2) ... Processing triggers for ureadahead (0.100.0-19) ... root@iZwz9fvt1y9kp07r5zpun6Z:~# docker -v Docker version 17.03.3-ce, build e19b718 root@iZwz9fvt1y9kp07r5zpun6Z:~#