无法从WSL连接到Docker

时间:2020-03-05 23:36:54

标签: 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的更新似乎不可用。

1 个答案:

答案 0 :(得分:0)

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

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

此外,这似乎是一个愚蠢的问题,但我不得不问,码头工人是否正确运行?如果您运行docker info,则从powershell中返回docker服务器的状态吗?