0

I am trying to start multiple services with docker-compose but I get

npm ERR! missing script: start

in my console when I run the docker-compose up command

Note I am able to start the each of the services individually with docker run command.

Below is a copy of my docker-compose.yml file

version: '3.4'

services:
  clientservice:
    image: clientapplication
    build:
      context: .
      dockerfile: ./client/Dockerfile
    environment:
      NODE_ENV: production
    ports:
      - "3000:3000"
    networks: 
      - blogmicroservice
  commentservice:
    image: commentsservice
    build:
      context: .
      dockerfile: ./comments/Dockerfile
    environment:
        NODE_ENV: production
    ports:
      - "4001:4001"
    networks: 
      - blogmicroservice
  moderationservice:
    image: moderationservice
    build:
      context: .
      dockerfile: ./moderation/Dockerfile
    environment:
      NODE_ENV: production
    ports: 
      - "4003:4003"
    networks: 
      - blogmicroservice
  postservice:
    image: postservice
    build:
      context: .
      dockerfile: ./posts/Dockerfile
    environment: 
      NODE_ENV: production
    ports: 
      - "4000:4000"
    networks: 
      - blogmicroservice
  eventbusservice:
    image: eventbus
    build:
      context: .
      dockerfile: ./event-bus/Dockerfile
    environment: 
      NODE_ENV: production
    ports: 
      - "4005:4005"
    networks: 
      - blogmicroservice
  queryservice:
    image: queryservice
    build: 
      context: .
      dockerfile: ./query/Dockerfile
    environment: 
      NODE_ENV: production
    ports: 
      - "4002:4002"
    networks: 
      - blogmicroservice
networks: 
  blogmicroservice:
    driver: bridge

An example of the docker file for individual service

FROM node:12.18-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "./"]
RUN npm install --production --silent 
COPY . .
EXPOSE 4002
CMD ["npm", "start"]

8
  • 1
    Do you see any error at layer npm install? The start script should be in package.json, so that's strange that docker-compose can run install but cannot find start script Commented Jul 7, 2021 at 13:26
  • Can you update the question with file structure? I suspect that the context is not correct Commented Jul 7, 2021 at 13:37
  • yes that was the issue.....changed the path in the context and it works fine now Commented Jul 7, 2021 at 15:03
  • just out of curiosity, do you see any error at layer npm install? Commented Jul 7, 2021 at 15:12
  • no ..no errors there .It installs the packages successfully Commented Jul 7, 2021 at 15:30

2 Answers 2

2

In the docker-compose file, all services are using the same context

build:
  context: .

Which means all files will be copied to docker daemon at build time. This is very unlikely to be the case because different apps cannot have the same code base. If each image can be properly run, then the problem may not lie in Dockerfile. You can change context to proper directory:

build:
  context: ./your-server

Note that when the value in context: supplied is a relative path, it is interpreted as relative to the location of the Compose file. This directory is also the build context that is sent to the Docker daemon.. So, you may not even need to specify the Dockerfile location.

Sign up to request clarification or add additional context in comments.

Comments

0

i resolved this ..the context in docker-compose.yml was out of place updated it to this and it startsup fine now

version: '3.4'

services:
  clientservice:
    image: clientapplication
    build:
      context: ./client
      dockerfile: ./Dockerfile
    environment:
      NODE_ENV: production
    ports:
      - "3000:3000"
    networks: 
      - blogmicroservice
  commentservice:
    image: commentsservice
    build:
      context: ./comments
      dockerfile: ./Dockerfile
    environment:
        NODE_ENV: production
    ports:
      - "4001:4001"
    networks: 
      - blogmicroservice
  moderationservice:
    image: moderationservice
    build:
      context: ./moderation
      dockerfile: ./Dockerfile
    environment:
      NODE_ENV: production
    ports: 
      - "4003:4003"
    networks: 
      - blogmicroservice
  postservice:
    image: postservice
    build:
      context: ./posts
      dockerfile: ./Dockerfile
    environment: 
      NODE_ENV: production
    ports: 
      - "4000:4000"
    networks: 
      - blogmicroservice
  eventbusservice:
    image: eventbus
    build:
      context: ./event-bus
      dockerfile: ./Dockerfile
    environment: 
      NODE_ENV: production
    ports: 
      - "4005:4005"
    networks: 
      - blogmicroservice
  queryservice:
    image: queryservice
    build: 
      context: ./query
      dockerfile: ./Dockerfile
    environment: 
      NODE_ENV: production
    ports: 
      - "4002:4002"
    networks: 
      - blogmicroservice
networks: 
  blogmicroservice:
    driver: bridge

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.