本文最后更新于 442 天前,其中的信息可能已经有所发展或是发生改变。
之前尝试在国内的 ECS 实例里安装 docker,尝试运行以下命令:
curl -fsSL https://get.docker.com | bash
结果如下:
ecs-user@iZ2vc4s2mp8t4ikopho8pnZ:~/frps$ sudo bash ./docker-installer.sh
# Executing docker install script, commit: 4c94a56999e10efcf48c5b8e3f6afea464f9108e
+ sh -c 'apt-get -qq update >/dev/null'
+ sh -c 'DEBIAN_FRONTEND=noninteractive apt-get -y -qq install ca-certificates curl >/dev/null'
+ sh -c 'install -m 0755 -d /etc/apt/keyrings'
+ sh -c 'curl -fsSL "https://download.docker.com/linux/debian/gpg" -o /etc/apt/keyrings/docker.asc'
+ sh -c 'chmod a+r /etc/apt/keyrings/docker.asc'
+ sh -c 'echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stable" > /etc/apt/sources.list.d/docker.list'
+ sh -c 'apt-get -qq update >/dev/null'
W: Failed to fetch https://download.docker.com/linux/debian/dists/bookworm/InRelease Could not handshake: Error in the pull function. [IP: 3.170.229.111 443]
W: Some index files failed to download. They have been ignored, or old ones used instead.
+ sh -c 'DEBIAN_FRONTEND=noninteractive apt-get -y -qq install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null'
E: Package 'docker-ce' has no installation candidate
E: Package 'docker-ce-cli' has no installation candidate
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
E: Couldn't find any package by regex 'containerd.io'
E: Unable to locate package docker-compose-plugin
E: Package 'docker-ce-rootless-extras' has no installation candidate
E: Unable to locate package docker-buildx-plugin
显然,download.docker.com 在国内访问不畅。阅读脚本内容,发现如下注释:
# Alternatively, use the script at https://test.docker.com, which uses the test
# channel as default.
#
# --mirror <Aliyun|AzureChinaCloud>
#
# Use the --mirror option to install from a mirror supported by this script.
# Available mirrors are "Aliyun" (https://mirrors.aliyun.com/docker-ce), and
# "AzureChinaCloud" (https://mirror.azure.cn/docker-ce), for example:
#
# $ sudo sh install-docker.sh --mirror AzureChinaCloud
也就是说,这个脚本是允许使用镜像源的,于是将安装命令改为:
curl -fsSL https://get.docker.com | bash -s -- --mirror Aliyun
再次执行即可安装成功。