在18.04中,“docker-ce”软件包没有安装候选项。

我正在按照Ubuntu上的官方Docker安装指南the official Docker installation guide进行docker-ce的安装。
当我执行sudo apt install docker-ce时,出现E: Package 'docker-ce' has no installation candidate
$ sudo apt-get update
Hit:1 http://gb.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://gb.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:3 http://gb.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
Reading package lists... Done

$ sudo apt-get install \
>     apt-transport-https \
>     ca-certificates \
>     curl \
>     software-properties-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ca-certificates is already the newest version (20180409).
curl is already the newest version (7.58.0-2ubuntu3).
software-properties-common is already the newest version (0.96.24.32.1).
The following NEW packages will be installed
  apt-transport-https
0 to upgrade, 1 to newly install, 0 to remove and 0 not to upgrade.
Need to get 1,692 B of archives.
After this operation, 152 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://gb.archive.ubuntu.com/ubuntu bionic/universe amd64 apt-transport-https all 1.6.1 [1,692 B]
Fetched 1,692 B in 0s (65.4 kB/s)               
Selecting previously unselected package apt-transport-https.
(Reading database ... 116694 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_1.6.1_all.deb ...
Unpacking apt-transport-https (1.6.1) ...
Setting up apt-transport-https (1.6.1) ...

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

$ sudo apt-key fingerprint 0EBFCD88
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

$ sudo add-apt-repository \
>    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
>    $(lsb_release -cs) \
>    stable"
Hit:1 http://gb.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://gb.archive.ubuntu.com/ubuntu bionic-updates InRelease                                                                                    
Hit:3 http://gb.archive.ubuntu.com/ubuntu bionic-backports InRelease                                                                                  
Get:4 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]                                                       
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                               
Fetched 64.4 kB in 0s (141 kB/s)
Reading package lists... Done

robin@xps:~/git/snapcraft.io$ sudo apt-get update
Hit:1 http://gb.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://gb.archive.ubuntu.com/ubuntu bionic-updates InRelease                                      
Hit:3 http://gb.archive.ubuntu.com/ubuntu bionic-backports InRelease                                                                                   
Hit:4 https://download.docker.com/linux/ubuntu bionic InRelease                                                                                        
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                                
Reading package lists... Done  

$ sudo apt-get install docker-ce
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'docker-ce' has no installation candidate

我的第一个想法是Docker还没有发布适用于Bionic的软件包(它非常新),但当我搜索“在Ubuntu 18.04上安装docker-ce”时,我找到了一份似乎针对18.04特定版本的指南,基本上给出了完全相同的安装说明,这至少表明对作者来说是有效的。

https://linuxconfig.org/how-to-install-docker-on-ubuntu-18-04-bionic-beaver

有人知道为什么这对我不起作用吗?

1还有其他选择:来自Docker Inc的快照,或者是docker.io上更近期的标准Ubuntu软件包:askubuntu: Docker-CE或docker.io软件包 - nealmcb
12019年7月仍然存在这个问题... 对我来说,sudo apt install docker.io 这个命令解决了我的问题。 - cowlinator
也许你忘记了第一步。 - Thanh Phạm
8个回答

如果你想在Ubuntu 18.04上安装docker-ce,请运行以下命令:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu `lsb_release -cs` test"
sudo apt update
sudo apt install docker-ce

运行以下命令来检查安装是否成功完成:
docker -v

应该输出:
Docker version 18.06.1-ce, build e68fc7a

9此外,在Ubuntu 19的情况下,只需将第三行中的bionic更改为disco - pkuderov
顺便说一下,该网址加上 "bionic" 和 "test" 只是一个发布路径-您可以检查该网址并按照该路径进行操作。似乎任何有效的路径都是可行的-某些版本的Ubuntu有其他稳定/夜间等发布版本。因此,对于任何未来的Ubuntu版本,都可以在那里检查其相应的发布情况。 - pkuderov
@pkuderov Docker ce不在那个仓库中,deb仅在containerd.io中提供(https://download.docker.com/linux/ubuntu/dists/disco/pool/stable/amd64/)。我不知道在这种情况下是否可以使用`bionic`代替`disco`。这真是令人沮丧。 - andras
@pkuderov 您可以相应地编辑回复 - Yuval Pruss
2伙计们,看起来自从版本18.09.0开始,后缀-ce-ee已经被移除了,所以据我所见没有错误。我检查了我的test构建的安装 - sudo docker run hello-world正常工作。我唯一看到的问题是19版本还在测试中。 抱歉让你困惑了 - 我才用Linux两周 :) - pkuderov
1我们能用 xenial 替换 bionic 吗?我刚在 Ubuntu 16.04 上尝试了一下,虽然 lsb_release -cs 的输出是 xenial,但似乎可以工作。 - Ibrahim.H
给初学者的小提示:逐行执行每一行代码。复制所有代码会将命令连接在一起,而不会执行一系列命令的最后一条。 - questionto42

从您引用的同一指南中,您可以在这个时刻使用17.10版本的存储库。
deb [arch=amd64] https://download.docker.com/linux/ubuntu artful stable

所有的docker-ce依赖包将从ubuntu bionic仓库中解决。请查看Docker文档获取更多信息。不需要担心兼容性问题:)

2018-07-19更新

Docker 18.06已经更新到bionic仓库,不再需要这个解决方法!


16在18.04上仍然无法工作。我仍然收到E: 包 'docker-ce' 没有可安装的候选版本 - R J
@RJ 在我的18.04版本上它是可以工作的。现在已经过了几天,也许存储库已经更新了一些内容。我注意到有些软件包是从bionic下载的,而其他软件包则是从artful下载的。 - NZD
https://github.com/docker/for-linux/issues/290#issuecomment-393605253 - mafrosis
我可以确认这个是工作正常的,刚刚在18.04上安装了它 ➜ ~ docker -v Docker版本为18.03.1-ce,构建版本为9ee9f40 - copser
2请参考,自6月21日起,可以使用以下命令安装:curl -fsSL get.docker.com | CHANNEL=stable sh - Juha Untinen
尝试这个:https://stackoverflow.com/a/55012230/1396526 - Teymur Mardaliyer Lennon
感谢您的提问。在安装软件之前,根据文档中的说明,需要进行多个步骤。 - FantomX1

我遇到了同样的问题,这是我解决的方法:
$ sudo snap install docker

$docker -v

Docker version 18.06.1-ce, build e68fc7a


$sudo docker version


Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.4
 Git commit:        e68fc7a
 Built:             Tue May  7 18:01:43 2019
 OS/Arch:           linux/386
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       e68fc7a
  Built:            Tue May  7 18:01:44 2019
  OS/Arch:          linux/386

那是最简单、最优雅的解决方案!只需先运行“sudo apt install snapd”即可 :) - d.popov
2除了注意到它安装的是 Docker 18 而不是 19,它基本上没有什么用处。 - James Moore
谢谢伙计。它起作用了。 - Ramesh Ponnusamy
1Docker Snap不再由Docker公司维护。最后发布的版本是17.06.2。Docker Snap的未来尚不明确,但它将不会在此处继续开发。 - Konrad Grzyb

一些指南过早地发布了消息;在本文发布时,docker-ce还不支持Ubuntu 18.04。您可以在这里查看支持的版本列表。
您提供的同一指南建议安装docker.io;这就是我所做的。这是一个临时解决方案,直到docker-ce支持18.04。

1从同一个指南中,您可以在此时使用17.10版本的存储库:deb [arch=amd64] https://download.docker.com/linux/ubuntu artful stable - tan9
@tan9 应该是被接受的答案 - 你能把它作为一个回答发布吗? - Robin Winslow
2我正在使用18.04版本,并且将URL指向artful对我没有帮助。唯一有效的方法是安装docker.io。 - R J

按照 Docker 文档中这里的步骤进行操作对我有效。我只需在此命令中将 stable 改为 test

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

为什么你非得这样做呢?你用的是哪个版本?能否提供你所使用的完整步骤? - Zanna
这在Ubuntu 18.04上不起作用,而问题就是关于它的。 - R J
它对我来说完全正常工作。 - xExplorer
@Zanna https://github.com/docker/for-linux/issues/290#issuecomment-393605253 - mafrosis

如果你遇到了错误信息“Package 'docker-ce' has no installation candidate”,那么请使用以下方法:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable edge test"

1除非你使用的是ARM架构(比如树莓派),否则你需要添加[arch=arm64] - msanford


1欢迎来到AU。你能否编辑你的回答,提供一份解决方案的摘要?这样,即使链接消失或更改,你的回答仍然有效。感谢你的努力。 - Marc Vanhoomissen

通过执行以下命令,我们可以安装Docker。
 curl -fsSL get.docker.com | CHANNEL=stable sh
 sudo apt install docker-ce
 sudo apt-get install docker-ce docker-ce-cli containerd.io