Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 425
smeeb Avatar asked Aug 22 '16 15:08

smeeb


People also ask

How do I make sure Docker is running on Mac?

On MacOS go to the whale in the taskbar > Preferences > Daemon > Advanced. You can also start the Docker daemon manually and configure it using flags. This can be useful for troubleshooting problems. Many specific configuration options are discussed throughout the Docker documentation.

Can't connect to the Docker daemon Mac?

Can't connect to the Docker daemon Mac? First, check if the Docker engine is running: sudo service docker status. If the Docker engine isn't working, start it with the following command: sudo service docker start. After you start the Docker engine, try running the docker-compose build command again.

Should nginx run inside Docker?

If nginx is running in a container then your site is going to be 100% dead to the world while Docker isn't running. Users will get a connection error. When nginx is installed directly on your host you can serve a 503 maintenance page that doesn't depend on Docker or any containers running.


2 Answers

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.

like image 85
Eugen Mayer Avatar answered Oct 22 '22 14:10

Eugen Mayer


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

like image 1
ssemichev Avatar answered Oct 22 '22 13:10

ssemichev