我已经在Windows上使用WSL2设置了Ubuntu 18.04,并完成了docker-ce和docker-compose的所有安装。我验证了我的安装。
$ sudo service docker start
以上命令成功启动了docker守护进程,但是当我尝试通过以下命令构建docker镜像时,
{path that contains yml files}$ docker-compose build
失败,并显示以下错误。
服务'comp_app'生成失败:获取https://registry-1.docker.io/v2/:拨打tcp:在172.25.240.1:53上查找注册表-1.docker.io:读取udp 172.25.254.229:49124->172.25.240.1:53 :I / O超时
我尝试杀死所有停下的容器,晃晃图像。甚至也重新启动了我的WSL。似乎没有一个工作。
答案 0 :(得分:0)
在WSL2下,您必须使用Windows上运行的docker-desktop,因为WSL2不支持真正的初始化系统。 为此:
function install_docker_on_linux_or_wsl2 () {
sudo apt update
sudo apt install -y 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 -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache policy docker-ce
# Note: on WSL2, this will only install the docker client, as there is no init system
# you need export DOCKER_HOST=tcp://localhost:2375 in your .bashrc or .zshrc file when running on WSL2
# docker desktop must be running, and the option to run unsecure on port 2375 (docker options) must be selected
sudo apt install -y docker-ce
}
之后,执行所有docker操作,例如码头工人图像应该工作。