Jeongkuk Seo
Jeongkuk Seo

Reputation: 165

Docker-compose node express container doesn't show error logs and restart continuously

I am trying to make nginx, node express work on the container by using docker compose.

But problem is express container doesn't show any error log why it is died.

This is my docker-compose.yml

version: '3'
services:
  proxy:
    image: nginx:latest
    container_name: proxy
    ports: 
      - "80:80"
    volumes:
      - ./proxy/nginx.conf:/etc/nginx/nginx.conf
    restart: "unless-stopped"  
  express:
    build:
      context: ./server
    container_name: express
    expose:
      - "3000"
    volumes:
      - ./source:/source
      - /source/node_modules
    restart: "unless-stopped"

This is my directory structure.

source directory, i move all files and directories from express-generator outputs.

enter image description here

This is my Dockerfile.

FROM node:12

COPY package*.json /source/
WORKDIR /source
RUN npm install

CMD [ "node", "app.js" ]

This is my package.json

 {
  "name": "docker_web_app",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "start": "node app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "sjk5766",
  "license": "ISC",
  "dependencies": {
    "cookie-parser": "~1.4.4",
    "debug": "~2.6.9",
    "express": "~4.16.1",
    "http-errors": "~1.6.3",
    "jade": "~1.11.0",
    "morgan": "~1.9.1"
  }
}

When i did docker ps after docker-compose up -d, result is like below. enter image description here

When i did docker logs express, there is nothing i can see.

I really wanna know what is the problem.

Upvotes: 0

Views: 1236

Answers (1)

Bhagyashri Machale
Bhagyashri Machale

Reputation: 219

Considering your express application is running fine without docker.

you can change your Dockerfile as below

FROM node:12

WORKDIR /source

COPY . .

RUN npm install

EXPOSE 3000

CMD [ "node", "app.js" ]

COPY command will copy your local directory code to /server directory in docker try docker-compose file as below

version: '3'
services:
  proxy:
    image: nginx:latest
    container_name: proxy
    ports: 
      - "80:80"
    volumes:
      - ./proxy/nginx.conf:/etc/nginx/nginx.conf
    networks:
      - test_bridge
    restart: "unless-stopped"
  express:
    build: ./server
    container_name: express
    ports:
      - "3000:3000"
    networks:
      - test_bridge
networks:
  test_bridge:
    driver: bridge

Upvotes: 1

Related Questions