Can't access docker container on port 80 on OSX

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

  • Is it feasible to create docker file for each service of my node project?
  • docker-compose error when I run bundle
  • Creating kubernetes cluster inside an existing VPC in AWS
  • Running Jenkins slave on different OS than master (and host)
  • Unable to compile cpp via docker in Travis-CI: /usr/bin/ld: cannot open output file a.out: Permission denied
  • How to search for containers that don't match the result of “docker ps --filter”?
  • 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.

  • Can I put kubernetes in a docker container?
  • Run docker image with docker-compose
  • Docker Consul service ip advertised as internal docker ip
  • Installing PostgreSQL within a docker container
  • Open CV error failed to init raw1394 persisting in docker
  • Is it possible to set maximum delay timeout for restart policy for a container?
  • 2 Solutions collect form web for “Can't access docker container on port 80 on OSX”

    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

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.