简体   繁体   English

在 Windows 10 Home 中在 WSL 上设置 docker 的问题

[英]Issue with setting up docker on WSL in Windows 10 Home

I am trying to setup docker through WSL (ubuntu) on Windows 10 Home but ran into an issue when trying to use the docker-compose up command:我正在尝试在Windows 10 Home上通过WSL (ubuntu) 设置 docker,但在尝试使用docker-compose up命令时遇到了问题:

$ docker-compose up
ERROR: Couldn't connect to Docker daemon at http://localhost:2375 - is it running?

I have the following configuration in my ~/.bashrc file我的~/.bashrc文件中有以下配置

#Insert new Path for Docker and Alias

PATH="$HOME/bin:$HOME/.local/bin:$PATH"

PATH="$PATH:/mnt/c/Program Files/Docker Toolbox"

alias docker=docker.exe

alias docker-machine=docker-machine.exe

// Other code

export DOCKER_HOST='tcp://localhost:2375'

docker-machine seems to be running fine as the docker ps command shows a list of containers. docker-machine 似乎运行良好,因为docker ps命令显示了一个容器列表。

From my research, if I were to use Docker for Windows (which does not run on Windows Home) ;根据我的研究,如果我将Docker 用于 Windows (不在 Windows Home 上运行); I need to turn on the “Expose daemon on tcp://localhost:2375 without TLS” option in the settings.我需要在设置中打开“在没有 TLS 的情况下在 tcp://localhost:2375 上公开守护进程”选项。 Since I am using “Docker Toolbox + VirtualBox”, I would like to ask what would be the equivalent?由于我使用的是“Docker Toolbox + VirtualBox”,请问什么是等价的?

Please let me know if you require further information.如果您需要更多信息,请告诉我。

This is a bit tricky because yo need to use two terminals : one in Windows and one in WSL.这有点棘手,因为您需要使用两个终端:一个在 Windows 中,一个在 WSL 中。

What worked for me : I installed docker-machine and virtualbox on Windows.什么对我有用:我在 Windows 上安装了 docker-machine 和 virtualbox。 Then I created a virtual machine named default on virtualbox.然后我在 virtualbox 上创建了一个名为 default 的虚拟机。 Then on Windows, with the terminal Git bash for windows, I ran the following commands :然后在 Windows 上,使用 Windows 的终端 Git bash,我运行了以下命令:

  1. docker-machine start default : it starts the virtual machine. docker-machine start default :它启动虚拟机。 Alternatively, you can start it directly on virtualbox或者,您可以直接在 virtualbox 上启动它
  2. docker-machine env default : it shows the commands needed to start the linux shell. docker-machine env default :它显示了启动 linux shell 所需的命令。

Output looks like this输出看起来像这样

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.101:2376"
export DOCKER_CERT_PATH="C:\Users\<yourusername>\.docker\machine\machines\default"
export DOCKER_MACHINE_NAME="default"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"
# Run this command to configure your shell:
# eval $("C:\ProgramData\chocolatey\lib\docker-machine\bin\docker-machine.exe" env default)

Then you switch to WSL.然后你切换到 WSL。 You can access the terminal by typing ubuntu in the research bar您可以通过在研究栏中键入 ubuntu 来访问终端

In /.bashrc, you paste the output (replace with your own output)在 /.bashrc 中,粘贴输出(替换为您自己的输出)

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.101:2376"
export DOCKER_CERT_PATH="/mnt/c/Users/<yourusername>/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
export COMPOSE_CONVERT_WINDOWS_PATHS="true"

Note that I changed the DOCKER_CERT_PATH so that it works on a linux environment请注意,我更改了 DOCKER_CERT_PATH 使其适用于 linux 环境

Finally, in WSL, run source /.bashrc最后,在 WSL 中,运行source /.bashrc

You can then test your install by running docker run hello-world Remember to keep your virtual machine running.然后,您可以通过运行docker run hello-world来测试您的安装 请记住保持您的虚拟机运行。

The following two articles really helped me with the install:以下两篇文章确实帮助我完成了安装:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM