34

I've installed Docker Toolbox in macOS and I'm following Docker's simple tutorial on deploying Nginx.

I've executed docker run and confirmed that my container has been created:

docker run --name mynginx1 -P -d nginx
docker ps
40001fc50719  nginx  "nginx -g 'daemon off"  23 minutes ago  Up 23 minutes  0.0.0.0:32770->80/tcp, 0.0.0.0:32769->443/tcp  mynginx1

however when I curl http://localhost:32770, I get a connection refused error:

curl: (7) Failed to connect to localhost port 32770: Connection refused

I'm struggling to see what I could have missed here. Is there an extra step I need to perform, in light of me being on macOS?

Jonathan
  • 13,947
  • 17
  • 94
  • 123
  • Check your nginx logs and/or increase verbosity. If I remember right this is a nginx issue where nginx is trying to reverse dns lookup or something like that. – user2105103 Oct 08 '15 at 18:51

4 Answers4

59

The issue is that your DOCKER_HOST is not set to localhost, you will need to use the IP address of your docker-machine, since you are using Docker Toolbox:

docker-machine ip default # should return your IP address.

See Docker Toolbox Docs for more information.

Michael
  • 10,124
  • 1
  • 34
  • 49
3
docker-machine ip default
xxx.docker.machine.ip

Then

curl http://xxx.docker.machine.ip:32770
Oldskool
  • 34,211
  • 7
  • 53
  • 66
alexis
  • 569
  • 5
  • 12
3

If you on OS X 10.10.3 Yosemite or newer and using Docker for Mac, you will not have docker-machine or docker toolbox or DOCKER_HOST to worry about.

Just map the port on run command local-port:container-port

docker run --name my-web  -p 8080:80
Code Tree
  • 2,160
  • 4
  • 26
  • 39
0

In Mac for versions above 10, you can try using "docker.for.mac.host.internal" instead of "localhost"

EDIT: docker.for.mac.host.internal is deprecated, they switched to host.docker.internal. Reference: https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds

Jaspreet Chhabra
  • 377
  • 3
  • 14