smeeb
smeeb

Reputation: 29537

Docker for Mac nginx example doesn't run

Mac 10.11.5 here. I am specifically trying to install Docker for Mac (not Docker Toolbox or any other offering). I followed all the instructions on their Installation page, and everything was going fine until they ask you to try running an nginx server (Step 3. Explore the application and run examples).

Running docker run hello-world worked beautifully with no problems at all. I was able to see the correct console output that was expected for that image.

However, they then ask you to try running an nginx instance:

docker run -d -p 80:80 --name webserver nginx

I ran this, and got no errors. Console output was expected:

Unable to find image 'nginx:latest' locally latest: Pulling from library/nginx
51f5c6a04d83: Pull complete 
a3ed95caeb02: Pull complete 
51d229e136d0: Pull complete 
bcd41daec8cc: Pull complete 
Digest: sha256:0fe6413f3e30fcc5920bc8fa769280975b10b1c26721de956e1428b9e2f29d04
Status: Downloaded newer image for nginx:latest
ae8ee4595f47e7057e527342783d035b224afd17327b057331529e2820fe2b61

So then I ran docker ps:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
ae8ee4595f47        nginx               "nginx -g 'daemon off"   12 seconds ago      Up 10 seconds       0.0.0.0:80->80/tcp, 443/tcp   webserver

So far so good. But then I open up my browser and point it to http://localhost and I get (in Chrome):

enter image description here

Any ideas where I'm going awry? I waited 5 mins just to give nginx/docker ample time to start up, but that doesn't change anything.


For tracking purposes, the related GitHub issue:

https://github.com/docker/for-mac/issues/393

Upvotes: 5

Views: 9166

Answers (4)

Jeevz
Jeevz

Reputation: 1

If you're running docker-machine, then run 'docker-machine ls' in your terminal and get the ip of your virtual host. Instead of typing in localhost, paste the virtual host's ip into your internet browser and it should work.

Upvotes: 0

Quang Tran
Quang Tran

Reputation: 1309

I had the same problem when run on Chrome, but it is work on Safari.

After a while pull my hair, i found out that my machine connected to a proxy, and this is problem. I must stop server, remove image, turn off proxy and pull it again.

Upvotes: -1

ssemichev
ssemichev

Reputation: 1441

Try curl -XGET `docker-machine ip`:80

Upvotes: 1

Eugen Mayer
Eugen Mayer

Reputation: 9924

corrected

The image exposes 80 as the httpd port https://github.com/nginxinc/docker-nginx/blob/11fc019b2be3ad51ba5d097b1857a099c4056213/mainline/jessie/Dockerfile#L25

So using -p 80:80 should work and does work for me:

docker run -p 80:80 nginx
172.17.0.1 - - [22/Aug/2016:17:26:32 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" "-"

So most probably you either run a httpd container on the host so the port cannot be binded ( should be visible through the start ) or you probably have an issue with localhost - does 127.0.0.1 work? You might have a issue with ipv6 then Or better using a docker-compose.yml file

version: '2'
services:
  webserver:
    image: nginx
    ports:
      - '80:80'

and the start it with docker-compose up - you can know easily add other services, like a tomcat, puma server, or a FPM upstream, whatever app you might have.

Upvotes: 6

Related Questions