Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection refused on nginx docker container

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?

like image 994
Jonathan Avatar asked Oct 08 '15 17:10

Jonathan


People also ask

Should nginx be in a Docker container?

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.

What is nginx Docker container?

Nginx (pronounced "engine-x") is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server). The nginx project started with a strong focus on high concurrency, high performance and low memory usage.


1 Answers

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.

like image 90
Michael Avatar answered Sep 20 '22 19:09

Michael