11

In my current job we have development environment made with docker-compose. One container is nginx, which provide routing to other containers. Everything seems fine and work to my colleague on windows and osx. But on my system (osx El Capitan), there is problem with accessing nginx container on port 80.

There is setup of container from docker-compose.yml

nginx:
    build: ./dockerbuild/nginx
    ports:
        - 80:80
    links:
        - php
    volumes_from:
        - app
... and more

In ./dockerbuild/nginx there is nothing special, just nginx config as we know it from everywhere.

When I run everyting with docker-compose create and docker-compose start. Then docker ps give me

3b296c1e4775        docker_nginx           "nginx -g 'daemon off"   About an hour ago   Up 47 minutes       0.0.0.0:80->80/tcp, 443/tcp        docker_nginx_1

But when I try to access it for example via curl I get error. curl: (7) Failed to connect to localhost port 80: Connection refused

I try to run container with port 81 and everything works fine.

Port is really binded to docker

22:47 $ sudo lsof -i -n -P | grep TCP
...
com.docke 14718         schovi   38u  IPv4 0x6e9c93c51ec4b617      0t0    TCP *:80 (LISTEN)
...

Firewall in osx is turned off and I have no other security.

Schovi
  • 1,960
  • 5
  • 19
  • 33

3 Answers3

7

if you are using docker-for-mac:

Accessing by localhost:80 is correct, though you still have to ensure you do not have a local apache/nginx service running. Often leftovers from boxen/homebrew exist binding that port, because thats what developers did back then :)

if you are using dockertoolbox/virtualbox/whatever hypervisor

You will not be able to access it by localhost, by by the docker-machine ip, so write docker-machine ip default and the use http://$ip:80 in your browser

if that does not help

Ensure your nginx container actually does work, so connect to the container: docker exec -i -t <containerid> bash

and then run ps aux nginx or if telnet is installed try to connect to localhost

Eugen Mayer
  • 8,942
  • 4
  • 33
  • 57
  • 1
    As I write in question I tried to switch container to port 81 and then localhost:81 open application in another container. But for some reason port 80 is not reachable even when container and nginx run and docker process is in list for port 80. – Schovi Sep 18 '16 at 16:02
  • Ensure you do not have a locally host based Webserver up and running, as written above – Eugen Mayer Sep 19 '16 at 05:54
  • had this from brew installed docker – user136776 Feb 15 '18 at 13:21
  • I had also docker installed via brew and had problems to connect to containers, I uninstalled via brew and re installed via docker for mac, it works now. – Paul Vincent Beigang Jun 26 '18 at 09:37
6

Solved!

Problem was, that long long time ago I installed pow (super simple automated rails server which run application on app_name.local domain). And this beast left LaunchAgent script which update pf to forward port 80 to pow port.

Schovi
  • 1,960
  • 5
  • 19
  • 33
  • 3
    you have a very generic question with a super specific answer, which will not be suitable as a general answer for your question. In you case, it could be software A, for the other its B, so explaining a general way of what could be the case, as i did, makes more sense. Downvoted your answer in this regard, even if it feels strange in the case that i have given the answer above - this answer does simply not help anybody (at all) – Eugen Mayer Jul 07 '17 at 13:53
  • 2
    I'd like to add, that to uninstall pow, you need to run the following command in the terminal: `curl get.pow.cx/uninstall.sh | sh` or read more about it at http://pow.cx/manual.html#section_1.2 – Andrew K Feb 03 '18 at 22:05
  • I had a similar problem, but with puma-dev: https://github.com/puma/puma-dev#uninstall – aNoble Aug 01 '21 at 05:47
  • In my case, the issue was being caused by MongoDB Compass. I closed this application and everything worked fine. Just in case somebody ends up with this scenario. Thanks – Jean Manzo Mar 17 '22 at 19:23
0

In my current job we have development environment made with docker-compose.

A privilege to use.

[W]hen I try to access [nginx on port 80] for example via curl I get error.

Given there's nothing from causing you from accessing docker on your host os you should look at the app running inside the container to ensure it's binding to the correct host, e.g. 0.0.0.0 and not localhost.

For example, if you're running Nuxt inside a container with nuxt-ts observe Nuxt will default to localhost thereby causing the container not to connect to the docker network whereas npx nuxt-ts -H 0.0.0.0 gets things squared away with the container's internal server connecting to the ip of the docker network used (verify ip like docker container inspect d8af01990363).

vhs
  • 9,316
  • 3
  • 66
  • 70