Issues docker with pm2 and nginx

Viewed 905

I'm having issues running a pm2 app on a container, I tried accessing through docker port and with an nginx proxy, but none of these solutions are working. Here's my docker config:

version: '3.5'

services:
  webapp:
    build:
      context: .
    image: ${DOCKER_IMAGE}
    container_name: mypm2app
    stdin_open: true 
    networks:
      - "default"
    restart: always
    ports:
      - "8282:8282"
    extra_hosts:
      - host.local:${LOCAL_IP}

  db:
    image: mongo:4.2.6
    container_name: mongodb
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
      MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
    volumes:
      - ${MONGO_SCRIPT_PATH}:${MONGO_SCRIPT_DESTINATION_PATH}
    networks:
      - "default"

networks:
  default:
    external:
      name: ${NETWORK_NAME}

Also I have this dockerfile:

FROM image
WORKDIR /var/www/html/path
COPY package.json /var/www/html/path
RUN npm install
COPY . /var/www/html/path
EXPOSE 8282/tcp
CMD pm2-runtime start ecosystem.config.js --env development

pm2 is starting the service, but I cannot access it through localhost:port. I tried to add an nginx proxy:

nginx:
        depends_on: 
          -  webapp
        restart: always
        build: 
            dockerfile: Dockerfile.dev
            context: ./nginx
        ports:
          -  "3002:80"
        networks:
          default: 
           ipv4_address: ${nginx_ip}$

with this docker-file

FROM nginx

COPY ./default.conf /etc/nginx/conf.d/default.conf

This is the nginx configuration, default.conf:

upstream mypm2app {
  server mypm2app:8282;
}

server {
        listen 80;
        server_name mypm2app.local;

        location /  {
                proxy_pass    http://mypm2app/;
        }
}

I would appreciate any suggestion or answer to this issue.

0 Answers
Related