Docker container not accessible in host machine

Some of my containers are running a web server (PHP, NodeJS) in production.

If we take the example of the NodeJS container, this is its configuration

  • How does mirror registry work in docker?
  • Docker - Pass a environment setting via docker-compose
  • How can i upload data to docker (container)?
  • Docker start container with custom command
  • Container as volume pattern in windows/vagrant env
  • how to do docker-compose pip install with a proxy?
  • docker-compose.yml

    version: '2'
        build: .
         - data
         - db:db
         - redis:redis
          - '8080:3000'
        restart: always

    With this configuration, I’m able to access to my webapp through but I cannot access on my host machine with

    $ curl localhost:8080

    I have a Nginx server on my host with this configuration:

    upstream webapp {
    server {
      listen 80;
      listen [::]:80;
      location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   HOST $http_host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-NginX-Proxy true;
        proxy_redirect off;
        proxy_pass http://webapp;

    But acceding to throw a 504 Gateway Time-out.

    If I try to change port configuration in my docker-compose.yml by '' the problem still here but cannot access to (and but it is the result I want).

    This is very strange and I don’t have the problem running my app on a fresh server.
    I’m searching for the root of this issue.

    Thanks for your support.


    $ netstat -tunlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address        State       PID/Program name
    tcp        0      0*               LISTEN      -               
    udp        0      0*                           -               

    Web server has to be listening on port 3000 but I have

    $ docker-compose logs
    webapp_1  | Express server listening on port 3000 in production mode

    The server is also running…

    $ docker port webapp_1
    3000/tcp ->

  • Deploying Docker images from Gitlab's private Docker registry to Openshift
  • Azure Docker Container - how to pass startup commands to a docker run?
  • How to setup environments for MERN apps
  • How to push docker images through reverse proxy to artifactory
  • How to reduce memory consumption of docker containers?
  • How to use Docker Swarm On Mesos?
  • One Solution collect form web for “Docker container not accessible in host machine”

    Edit: This should work similar to how you have it, did you try changing:
    proxy_set_header HOST $http_host;
    proxy_set_header HOST $host;
    in your nginx config?

    You could put nginx in your Docker Compose file and let Compose use its own network. If you want to add items in another network, you can specify a custom network, see:

    Otherwise, you can look at the output of ifconfig, etc on your host and see which IP and network Compose is using and what the host is listening to.

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