docker - 无法从WSL连接到Docker

标签 docker windows-subsystem-for-linux

我已经在Windows的docker中检查了Expose the daemon on tcp...选项,现在正尝试从WSL连接。我已经运行了所有这些命令:

# Update the apt package list.
sudo apt-get update -y

# Install Docker's package dependencies.
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

# Download and add Docker's official public PGP key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify the fingerprint.
sudo apt-key fingerprint 0EBFCD88

# Add the `stable` channel's Docker upstream repository.
#
# If you want to live on the edge, you can change "stable" below to "test" or
# "nightly". I highly recommend sticking with stable!
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# Update the apt package list (for the new apt repo).
sudo apt-get update -y

# Install the latest version of Docker CE.
sudo apt-get install -y docker-ce

# Allow your user to access the Docker CLI without needing root access.
sudo usermod -aG docker $USER

echo "export DOCKER_HOST=tcp://localhost:2375" >> ~/.bashrc && source ~/.bashrc

但是,docker info仅给我:
Client:
 Debug Mode: false

Server:
ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
errors pretty printing info

可能是什么问题?我整天都在尝试。我正在运行WSL和Ubuntu 18.04,而不是WSL 2,因为如果没有内部构建,带来WSL 2的更新似乎不可用。

最佳答案

如果运行env | sort,会看到DOCKER_HOST=tcp://localhost:2375变量吗?如果不是,则可能需要运行source ~/.bashrc将新的环境变量加载到当前控制台中。

或者,启动一个新的终端实例。

另外,这似乎是一个愚蠢的问题,但我不得不问, docker 是否正确运行?从powershell中,如果您运行docker info,它是否会返回docker服务器的状态?

关于docker - 无法从WSL连接到Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60555525/

相关文章:

docker - 如何在 Ubuntu 14.04 Dockerfile 中更新我的根证书?

amazon-web-services - 如何使用 Docker for Mac 向 docker awslogs 驱动程序提供凭据?

ubuntu-12.04 - 在禁用用户命名空间的情况下运行 docker 是否存在已知的安全风险?

ruby-on-rails - 通过本地网络连接到 WSL2 服务器

c# - OmniSharp MSBuild ProjectManager 无法更新我的 .csproj 文件

python - 如何从 python 运行 docker 命令?

Docker-compose不将环境变量传递给docker容器

linux - windows子系统Linux在终端中找不到文件

docker - 无法连接到 wsl 2 上的 debian buster 上的 Docker 守护进程

git - 为什么使用 SourceTree 的 WSL2 上的 Git 对我来说这么慢?