无法在亚马逊 Linux 实例上安装 Docker

9

我的实例使用这个 AMI:amzn2-ami-hvm-2.0.20191116.0-x86_64-gp2 (ami-01f14919ba412de34)。我想要按照这个文档安装 Docker,下面是我的命令输出:

[ec2-user@ip-10-193-192-42 ~]$ sudo amazon-linux-extras install docker
Installing docker
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker docker-ce-stable
12 metadata files removed
6 sqlite files removed
0 metadata files removed
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                               | 2.4 kB     00:00
amzn2extra-docker                                        | 1.3 kB     00:00
docker-ce-stable                                         | 3.5 kB     00:00
(1/6): amzn2-core/2/x86_64/group_gz                        | 2.6 kB   00:00
(2/6): amzn2-core/2/x86_64/updateinfo                      | 174 kB   00:00
(3/6): docker-ce-stable/x86_64/updateinfo                  |   55 B   00:00
(4/6): docker-ce-stable/x86_64/primary_db                  |  37 kB   00:00
(5/6): amzn2extra-docker/2/x86_64/primary_db               |  59 kB   00:00
(6/6): amzn2-core/2/x86_64/primary_db                      |  36 MB   00:00
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:18.09.9ce-2.amzn2 will be installed
--> Processing Dependency: runc = 1.0.0 for package: docker-18.09.9ce-2.amzn2.x8                                                                                        6_64
--> Processing Dependency: containerd = 1.2.6 for package: docker-18.09.9ce-2.am                                                                                        zn2.x86_64
--> Processing Dependency: pigz for package: docker-18.09.9ce-2.amzn2.x86_64
--> Processing Dependency: libcgroup for package: docker-18.09.9ce-2.amzn2.x86_6                                                                                        4
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.10-3.2.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.i                                                                                        o-1.2.10-3.2.el7.x86_64
---> Package libcgroup.x86_64 0:0.41-21.amzn2 will be installed
---> Package pigz.x86_64 0:2.3.4-1.amzn2.0.1 will be installed
--> Finished Dependency Resolution
Error: Package: containerd.io-1.2.10-3.2.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
Installation failed. Check that you have permissions to install.
[ec2-user@ip-10-193-192-42 ~]$

如何让它工作?
编辑
我的实例在自动扩展组中,因此我终止了之前的实例,并尝试在新的实例中进行Docker安装:
我已经安装了docker,但是当我运行命令时:
sudo service docker start

我从实例中注销并收到了一个错误窗口:

network error: software caused connection abort

有任何线索为什么会发生这种情况吗?

Requires: container-selinux >= 2:2.74 try installing this package first using yum install -y container-selinux >= 2:2.74 - error404
[ec2-user@ip-10-193-192-42 ~]$ sudo yum install -y container-selinux >= 2:2.74 Error: Nothing to do - Souad
我会推荐使用针对Docker优化的ECS-AMI来运行Docker。 - Adiii
https://stackoverflow.com/questions/47579041/installing-docker-on-redhat-linux-issue-with-container-selinux-and-selinux - error404
@error404 请检查问题的编辑部分。事实上,我成功安装了Docker,但是在运行docker start服务后,我失去了与实例的连接,现在无法通过ssh登录。 - Souad
您没有此处的权限。"安装失败。请检查您是否有安装权限。" - Frank AK
3个回答

20

刚刚尝试在完全相同的AMI上安装Docker,一切顺利。我猜你遇到了问题,是因为有一个名为docker-ce-stable的额外repo。在Amazon Linux 2 AMI上不需要它,因此,一旦您获得对新实例的SSH访问权限,请执行以下操作:

sudo amazon-linux-extras install docker

而且你应该没问题。


23
我也遇到了同样的问题,如果你是按照 Docker 文档操作的话,只需要删除仓库并运行该命令即可。如果你是新手,可以使用以下命令删除仓库:sudo rm /etc/yum.repos.d/docker-ce.repo。 - Rancor
2
天啊,这显然就是我的问题所在。谢谢@rancor。 - Josh Yolles
是的,这就是问题所在,我在Linux上使用了正常的安装方式。 - Amon
1
@Rancor 谢谢。这里有效了。大多数人在按照 Docker 的说明后才来到这里。 - Victor Ferreira
1
我不知道其他指令或脚本是否已更改,但我发现需要删除的是:/etc/yum.repos.d/download.docker.com_linux_centos_7_x86_64_stable.repo。 - johnfo

4

我遇到了相同的问题,但是用不同的方法解决了。

在您的亚马逊Linux 2盒子中检查是否存在一个名为

/etc/yum.repos.d/docker-ce

您应该删除它,然后运行安装命令即可解决问题。

sudo amazon-linux-extras install docker

0
你可以使用cloud-init作为设置的一部分来为你设置Docker。Terraform也可以很容易地实现。
这是我的Terraform模块中的部分,它将使用cloud-init为你设置Docker。
请注意,这是在Amazon Linux 3上,默认包含amzn2extra-docker仓库。
#cloud-config
repo_update: true
repo_upgrade: all
packages:
  - docker

此外,我推荐以下内容。
manage_resolve_conf: true
resolve_conf:
  name_servers: [ '169.254.169.253' ]

默认的DNS与您的主机位于同一个子网中,这可能会导致Docker创建容器的子网与之相同,从而使生活变得有些尴尬。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接