windows Docker 工具箱 - 本地主机不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42866013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:50:56  来源:igfitidea点击:

Docker Toolbox - Localhost not working

windowsdockerdocker-toolbox

提问by Mark

So I'm using Docker Toolbox because I don't have Hyper-V on my machine since it's not Windows 10 pro. Everything seems to work fine, but when I try to go on my browser 0.0.0.0:80it always returns me: This site can't be reached

所以我使用 Docker Toolbox 是因为我的机器上没有 Hyper-V,因为它不是 Windows 10 专业版。一切似乎都正常,但是当我尝试打开浏览器时,0.0.0.0:80它总是返回:无法访问此站点

But when I run the command: docker container psI get the following: 0.0.0.0:80->80/tcpmeaning that this address should work. I searched across stackoverflow and github issues. Now I'm stuck.

但是当我运行命令时:docker container ps我得到以下信息:0.0.0.0:80->80/tcp意味着这个地址应该可以工作。我搜索了 stackoverflow 和 github 问题。现在我被困住了。

Am I missing something?

我错过了什么吗?

Thanks, Mark

谢谢,马克

EDIT:

编辑:

Using docker-machine ip defaultreturns me 192.168.99.100. I run that on port 80. I still get the same result except that the address becomes the container id: https://fd677edg12

使用docker-machine ip default返回我192.168.99.100。我在端口 80 上运行它。除了地址变成容器 id 之外,我仍然得到相同的结果:https://fd677edg12

I run that command on cmd to find my ipv4: cmd /k ipconfig /all. Put the result with the port and it returns the same thing: https://fd677edg12

我在 cmd 上运行该命令以找到我的 ipv4: cmd /k ipconfig /all。将结果与端口放在一起,它返回相同的内容:https://fd677edg12

回答by Bret Fisher

Docker Toolbox doesn't get as many conveniences as Docker for Windows, but you're correct in using it since you're on Home edition.

Docker Toolbox 没有 Docker for Windows 带来的便利,但您使用它是正确的,因为您使用的是家庭版。

In Toolbox, nothing will be localhost, and will be 192.168.99.100by default, since it's running a Linux VM in VirtualBox.

在 Toolbox 中,默认情况下localhost不会有任何内容192.168.99.100,因为它在 VirtualBox 中运行 Linux VM。

So if you run docker run -p 80:80 nginx

所以如果你跑 docker run -p 80:80 nginx

(notice I had to publish a port for 192.168.99.100to listen on that port)

(注意我必须发布一个端口192.168.99.100来监听那个端口)

Then going to http://192.168.99.100should work.

然后去http://192.168.99.100应该工作。

回答by EJJ

I initially had a few issues with accessing my Applications at localhost:8080 while using DockerToolBox and OracleVM VirtualBox.

在使用 DockerToolBox 和 OracleVM VirtualBox 时,我最初在 localhost:8080 上访问我的应用程序时遇到了一些问题。

In VirtualBox:

在 VirtualBox 中:

  1. Click the appropriate machine (probably the one labeled "default")
  2. Settings
  3. Network > Adapter 1 > Advanced > Port Forwarding
  4. Click "+" to add a new Rule
  5. Set Host Port 8080& Guest Port 8080; be sure to leave Host IP and Guest IP empty
  1. 单击适当的机器(可能是标记为“默认”的机器)
  2. 设置
  3. 网络 > 适配器 1 > 高级 > 端口转发
  4. 单击“+”添加新规则
  5. 设置主机端口8080和访客端口8080;确保将主机 IP 和访客 IP 留空

Run the command:

运行命令:

docker run -p 8080:8080 ${image_id}

回答by nitya wijayanti

I was following docker for windows tutorial in https://docs.docker.com/docker-for-windows/#set-up-tab-completion-in-powershelland got stuck in step #6 when test nginx in the web browser. Seems I faced a similar problem since I also use Windows Home and don't have Hyper-V. My workaround is quite simple:

我在https://docs.docker.com/docker-for-windows/#set-up-tab-completion-in-powershell 中关注 docker for windows 教程,但在 Web 浏览器中测试 nginx 时卡在了第 6 步. 似乎我遇到了类似的问题,因为我也使用 Windows Home 并且没有 Hyper-V。我的解决方法很简单:

  1. check your docker IP default
  1. 检查您的 docker IP 默认值

$ docker-machine ip default

192.168.99.100

$ docker-machine ip 默认

192.168.99.100

  1. Go to Oracle Virtual Machine to set for port forwarding. Make sure the network setting is NAT, and add port forwarding. Host IP: 127.0.0.1, Guest IP: 192.168.99.100, port all set to 80 like this

  2. Try again to your browser and run http://localhostor http://127.0.0.1(can add the port 80 also). It should run.

  1. 转到 Oracle 虚拟机以设置端口转发。确保网络设置为 NAT,并添加端口转发。主机IP:127.0.0.1,游客IP:192.168.99.100,端口都设置为80 这样的

  2. 再次尝试在浏览器中运行http://localhosthttp://127.0.0.1(也可以添加端口 80)。它应该运行。

The thing is that the nginx IP is meant to be accessible within the docker Virtual Machine, so that we need that port forwading setting in order to access it directly in the host machine's browser

问题是 nginx IP 意味着可以在 docker 虚拟机中访问,因此我们需要该端口转发设置才能直接在主机的浏览器中访问它

回答by Bablu Ahmed

You can use localhostinstead of '192.168.99.100' by following the instructions:

您可以localhost按照说明使用“192.168.99.100”代替“192.168.99.100”:

Step #01:

步骤#01:

docker-machine ip default

You will see the default IP

您将看到默认IP

Step #02:

步骤#02:

docker-machine stop default

Step #03:

步骤#03:

  1. Open VirtualBox Manager (from the start programs in windows search for VirtualBox Manager)
  2. Select your Docker Machine VirtualBox image (e.g.: default)
  3. Open Settings -> Network -> Advanced -> Port Forwarding
  4. Add your app name, the desired host port and your guest port i.e, app name : nginx, host: 127.0.0.1, host port: 80, guest port: 80
  1. 打开 VirtualBox Manager(从 windows 中的启动程序中搜索VirtualBox Manager
  2. 选择您的 Docker 机器 VirtualBox 映像(例如:默认)
  3. 打开设置->网络->高级->端口转发
  4. 添加您的应用程序名称、所需的主机端口和访客端口 i.e, app name : nginx, host: 127.0.0.1, host port: 80, guest port: 80

Step #04:Now you're ready to start your Docker Machine by executing the following:

步骤 #04:现在您已准备好通过执行以下命令来启动您的 Docker 机器:

docker-machine start default

Then just start your Docker container and you will be able to access it via localhost.

然后只需启动您的 Docker 容器,您就可以通过 localhost 访问它。

Have a look herefor details.

详情请看这里

回答by James Irwin

To map the ports expected to localhostinstead of hitting the docker-machine IP directly, you can use the VirtualBox CLI.

要映射预期的端口localhost而不是直接访问 docker-machine IP,您可以使用 VirtualBox CLI。

If the docker-machine VM (here called default) is running, add and delete rules like this:

如果 docker-machine VM(此处称为default)正在运行,请添加和删除如下规则:

> VBoxManage.exe controlvm "default" natpf1 "nginx,tcp,,8888,,8888"
> VBoxManage.exe controlvm "default" natpf1 delete nginx

If the VM is not running, or you want to stop before altering it:

如果 VM 未运行,或者您想在更改它之前停止:

> docker-machine stop
> VBoxManage.exe modifyvm "default" --natpf1 "nginx,tcp,,8888,,8888"
> VBoxManage.exe modifyvm "default" --natpf1 delete "nginx"
> docker-machine start

Where the format of the port forwarding rule is [<name>],tcp|udp,[<hostip>],<hostport>,[<guestip>], <guestport>.

其中端口转发规则的格式是[<name>],tcp|udp,[<hostip>],<hostport>,[<guestip>], <guestport>.

Note that in VirtualBox, you want to map to the hostport of Docker map, not the internal container port. You're mapping host -> VM, then Docker maps VM -> container.

注意在VirtualBox中,你要映射到Docker map的主机端口,而不是容器内部端口。您正在映射主机 -> VM,然后 Docker 映射 VM -> 容器。

See the VirtualBox docs.

请参阅VirtualBox 文档

回答by Rasso

This is another easy way to avoid typing the ip 192.168.99.100. Go to C:\Windows\System32\drivers\etc\hostsand add at the end of the file:

这是避免输入 ip 192.168.99.100 的另一种简单方法。转到C:\Windows\System32\drivers\etc\hosts并在文件末尾添加:

192.168.99.100 docker.awesomeor any name of your liking.

192.168.99.100 docker.awesome或任何您喜欢的名字。

Save the file (You need to have admin rights so make sure you right click on the file and run as administrator to be able to save it when you edit it).

保存文件(您需要具有管理员权限,因此请确保右键单击该文件并以管理员身份运行,以便在编辑时能够保存它)。

Go to your chosen domain name, docker.awesome:8080in this case and there you have it.

转到您选择的域名,在本例中为docker.awesome:8080,就可以了。