Osedea / nodock

Docker Compose for Node projects with Node, MySQL, Redis, MongoDB, NGINX, Apache2, Memcached, Certbot and RabbitMQ images
http://nodock.io
MIT License
762 stars 189 forks source link

nginx 502 error #100

Closed shahriar-shojib closed 3 years ago

shahriar-shojib commented 6 years ago

Hello, I am currently using nodock and my node app is running inside the container on 8000. Here's a response inside the container: root@11757b94d64a:/opt/app# curl -I localhost:8000 HTTP/1.1 200 OK cache-control: no-cache Date: Fri, 23 Mar 2018 09:13:55 GMT Connection: keep-alive

And on nginx container, I see this: location / { proxy_pass http://node:8000; }

I don't have much experience in docker, and I am not sure why it's not working. Also, I have modified the docker-composer file and removed the folders and it's configs that I don't need, could that be the problem? Please let me know. Shahriar

shahriar-shojib commented 6 years ago

[error] 6#6: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: , request: "HEAD / HTTP/1.1", upstream: "http://172.19.0.2:8000/", host: "localhost" I see this on nginx error log, do I need to expose the 8000 port on docker-compose?

philtrep commented 6 years ago

Hey @shahriar-shojib , Node is exposing the port 8000 to NGINX which in turn forwards it to 80.

It is possible that something broke but it seems like you might have an error in your node application, you may want to try manually running the application. Here's how:

In the docker-compose.yml, edit the entrypoint in the node service to the following:

entrypoint: run-nodock "sleep infinity"

then restart NoDock

docker-compose down
docker-compose up --build -d node nginx

you can now go inside the node container

docker-compose exec node bash

and run the application manually.

node <yourentrypoint>

Don't forget that your node application should be using port 8000.

Let me know how it goes!

shahriar-shojib commented 6 years ago

After following your instructions:

root@4fbecc4cde0e:/opt/app# node index.js
Set {}
(node:33) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
Server running at: http://localhost:8000

From VM:

root@leb:~# curl -I localhost:8000
curl: (52) Empty reply from server

From VM:

curl -I localhost:
HTTP/1.1 502 Bad Gateway
Server: nginx
Date: Fri, 23 Mar 2018 13:34:54 GMT
Content-Type: text/html
Content-Length: 166
Connection: keep-alive

From docker container(node) :

root@leb:~# docker exec -it 4fbecc4cde0e /bin/bash
root@4fbecc4cde0e:/opt/app# curl -I localhost:8000
HTTP/1.1 200 OK
cache-control: no-cache
Date: Fri, 23 Mar 2018 13:36:02 GMT
Connection: keep-alive

My Docker compose file:

version: '3.3'

services:

    node:
        build:
            context: ./node
            args:
                - NODE_VERSION=latest
                - PROJECT_PATH=/opt/app/
                - NODE_ENV=production
                - YARN=false
        volumes:
            - /docker/nodeapp:/opt/app
        entrypoint: run-nodock "sleep infinity"
        tty: true
        ports:
          - "8000:8000"

    nginx:
        build:
            context: ./nginx
            args:
                - WEB_REVERSE_PROXY_PORT=8000
                - WEB_SSL=false
                - SELF_SIGNED=false
                - NO_DEFAULT=false
        volumes:
            - ./data/logs/nginx/:/var/log/nginx
            - ./certbot/certs/:/var/certs
        ports:
            - "80:80"
            - "443:443"
        tty: true

    certbot:
        build:
            context: ./certbot
        links:
          - nginx
        volumes:
          - ./certbot/letsencrypt/:/var/www/letsencrypt
          - ./certbot/certs/:/var/certs