0

I am trying to communicate my frontend container with my nodejs backend container. In the docker cli when I ping to other container it shows no error but In the browser hitting localhost returns me a "504 Gateway Time-out"

docker-compose.yml

version: '3'

services:
    nodejs-app:
        build:
          context: ./nodedocker_app
        container_name: nodejsserver
        hostname: nodejsserver
        ports:
            - "3000:3000" 
        networks:
            - example-net

        depends_on:
            - mongo
    mongo:
        container_name: mongo
        image: mongo
        volumes:
            - ./data:/data/db
        ports:
            - "27017:27017" 
        networks:
            - example-net 
    nginx:
        build:
          context: ./nginx
        container_name: nginx
        hostname: nginx
        ports:
            - "80:80" 
        depends_on:
            - nodejs-app
        networks:
            - example-net

networks:
  example-net:
    external: true

default.conf (nginx)

server {
  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://nodejsserver:3000;
  }
}
Manas S. Roy
  • 303
  • 1
  • 10
  • What URL exactly are you trying to reach? What is the exact error? If it's going into the Nginx reverse proxy, are there details in its log, and can you directly reach the back-end server via its published `ports:`? – David Maze Oct 17 '22 at 13:14
  • Thanks for you reply. I can not access any ports now. Though I am not getting any errors in logs also. Only error is I am getting 504 time out. This is a test project in got from youtube. What I am trying to reach is- I want to call my backend by reverse proxy in the frontend side. But for me the reverse proxy is not working. everything is in docker-compose. – Manas S. Roy Oct 17 '22 at 13:24
  • 1
    https://stackoverflow.com/questions/39070547/how-to-expose-a-docker-network-to-the-host-machine check this. – Sachith Muhandiram Oct 17 '22 at 13:44

0 Answers0