Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My docker container isn't starting on localhost (0.0.0.0) on Docker for Windows (Native using Hyper-V)

Tags:

docker

nginx

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:\>
like image 318
sgarcia.dev Avatar asked Jun 23 '16 13:06

sgarcia.dev


People also ask

How do I run a Docker container in localhost?

A simple solution to this in a Linux machine is to use the --network=”host” option along with the Docker run command. After that, the localhost (127.0. 0.1) in your Docker container will point to the host Linux machine. This runs a Docker container with the settings of the network set to host.

Can Docker run natively on Windows?

The Docker platform runs natively on Linux (on x86-64, ARM and many other CPU architectures) and on Windows (x86-64). Docker Inc. builds products that let you build and run containers on Linux, Windows and macOS.

Is wsl2 required for Docker?

However, since WSL 2 now runs on a Linux kernel with full system call capacity, Docker can fully run in WSL 2. This means that Linux containers can run natively without emulation, resulting in better performance and interoperability between your Windows and Linux tools.

Is Docker native on Windows 10?

Docker only supports Docker Desktop on Windows for those versions of Windows 10 that are still within Microsoft's servicing timeline. Containers and images created with Docker Desktop are shared between all user accounts on machines where it is installed.


2 Answers

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

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

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

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

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

enter image description here

like image 131
Ali Dehghani Avatar answered Oct 11 '22 12:10

Ali Dehghani


Despite you created the containers in your local machine. These are actually running on a different machine (a virtual machine)

First, check what is the IP of your docker machine (the virtual machine)

$docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM
default   *        virtualbox   Running   tcp://192.168.99.100  

Then run curl command (or open a browser) to view the default web site on your nginx web server inside the container

curl http://192.168.99.100:80
like image 44
Hemerson Varela Avatar answered Oct 11 '22 12:10

Hemerson Varela