How Dockerfiler uses multiple CMD commands

use CMD to run npm start (port 3000) and node. / server/server.js (port 8080) in Dockerfile

Dockerfile:

FROM node:8.9-alpine

ENV NODE_ENV production

WORKDIR /usr/src/app

COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]

RUN npm install --production --silent && mv node_modules ../

COPY . .

CMD [ "npm", "start", "node", "./server/server.js" ]

you can only open port 3000 locally

Project directory:

docker-compose.yml:

version: "2.1"

services:
  chat:
    image: chat
    container_name: chat
    build: .
    environment:
      NODE_ENV: production
    ports:
      - "3000:3000"
      - "8080:8080"
    volumes:
      - ./:/usr/src/app
    links:
      - mongo
  mongo:
    container_name: mongo
    image: mongo
    ports:
      - "27017:27017"

there are two ways. One is that CMD does not need brackets and links commands with "& &" symbols:

-sharp nohupnpm start
CMD nohup sh -c 'npm start && node ./server/server.js'

another way is not to use the CMD, ENTRYPOINT command, specify an executed shell script, and then write the command to be executed in the entrypoint.sh file:

ENTRYPOINT ["./entrypoint.sh"]

the entrypoint.sh file is as follows:

// entrypoint.sh
nohup npm start &
nohup node ./server/server.js &

I hope I can help you.


how to run multiple program processes in one Docker

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7c1f58-2a904.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7c1f58-2a904.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?