在 wsl 上构建 docker 图像

Building a docker image on wsl

我买了一台新机器,现在第一次使用 wsl 而不是 ubuntu。我正在尝试重建我的一个项目,但我无法构建 docker 图像。

当 运行 docker-compose build 我得到错误:

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?                                                                                                                
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

我试过了运行:

systemctl start docker

但是我得到了错误:

System has not been booted with systemd as init system (PID 1). Can't operate.                    
Failed to connect to bus: Host is down 

谁能告诉我我做错了什么,谢谢。

在 WSL 中,您实际上想使用来自 Windows 主机的 Docker:

  1. 为 Windows
  2. 安装 Docker 桌面
  3. 转到设置 > 资源 > WSL 集成,然后打开要启用 Docker 的发行版的开关。
  4. 您现在应该能够在 WSL 命令行中 运行 docker -v 并获得 Docker 版本的输出