本文介绍了Docker for Windows(本机使用Hyper-V)上的docker容器不是在localhost(0.0.0.0)上启动的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在追踪


I'm following Digital Ocean's tutorial on how to start a nginx docker container (Currently on Step 4). Currently this is their output:

$ docker run --name docker-nginx -p 80:80 -d nginx
d3ccb73a91985651ec61231bca9f9c716f0dec807e354a29eeef2144f883a01c

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                         NAMES
b91f3ce26553        nginx               "nginx -g 'daemon off"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 443/tcp   docker-nginx

But when I run it, this is my output (noticed the different IP of the container):

C:\>docker run --name docker-nginx -p 80:80 -d nginx
d3ccb73a91985651ec61231bca9f9c716f0dec807e354a29eeef2144f883a01c

C:\>docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                           NAMES
d3ccb73a9198        nginx               "nginx -g 'daemon off"   14 hours ago        Up 2 seconds        10.0.75.2:80->80/tcp, 443/tcp   docker-nginx

Why does this happen? And how can I get the same results as Digital Ocean's? (Getting the server to start on localhost)


Edit: I'm using Docker for windows (recently released) which apparently runs native using Hyper-V. My output for docker-machine ls is this:

C:\>docker-machine ls
NAME   ACTIVE   DRIVER   STATE   URL   SWARM   DOCKER   ERRORS

C:\>
解决方案

Since this a Windows machine, I assume that you're using Docker for Windows. 10.0.75.2 is the IP of the virtual machine.

If you are using Windows or Mac OS, you will need some form of virtualization inorder to run Docker. The IP you just saw is the IP of that lightweight virtual machine.

Use a Linux distribution! Also you can enable Expose container ports on localhost in Docker For Windows Settings:

这篇关于Docker for Windows(本机使用Hyper-V)上的docker容器不是在localhost(0.0.0.0)上启动的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 12:10