13

I am trying to wire up my Angular 7 client app into docker compose locally.

I get the following error when I docker-compose up:

client-app    | npm ERR! errno -2
client-app    | npm ERR! syscall open
client-app    | npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'

Dockerfile:

FROM node:9.6.1

RUN mkdir -p /app
WORKDIR /app
EXPOSE 4200

ENV PATH /app/node_modules/.bin:$PATH

COPY . /app

RUN npm install --silent
RUN npm rebuild node-sass

CMD ["npm", "run", "docker-start"]

The compose part for the client is:

  client-app:
    image: ${DOCKER_REGISTRY-}client
    container_name: client-app
    ports:
      - "4200:81"
    build:
      context: .
      dockerfile: ClientApp/Dockerfile

package.json is in the ClientApp folder along-side Dockerfile, I would assume COPY . /app should copy the package.json to the container. I don't have any excludes in dockerignore. I am using Docker for Windows with Unix containers. I tried npm init before (but that will create an empty package.json anyway) and looked through the SO posts but most of the dockerfile definitions look exactly the same. I also tried: COPY package*.json ./ additionally and building the image with --no-cache.

2 Answers 2

18

Your Dockerfile is fine, and COPY package*.json ./ is not necessary - its being copied with your entire app.

The problem is in your docker-compose file.

you defined:

build:
      context: .
      dockerfile: ClientApp/Dockerfile

that means, your Dockerfile will accept the docker-compose context, which is 1 directory above:

├── docker-compose.yml -- this is the actual context
└── ClientApp
    ├── Dockerfile -- this is the expected context

so when the CMD is running, it is 1 directory above the package.json, therefore it cannot run the command and the container exits.

to fix it, give your docker-compose file the correct context:

build:
      context: ClientApp
      dockerfile: Dockerfile

and it should work.

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

1 Comment

Thanks Efrat @Kirill Ermolov, this solved the issue, I prefer the approach with docker compose since I want to sometimes run the client separately for CI unit tests and leaving it with one working dockerfile seems a better option.
3

This command COPY package*.json ./ will try copy package.json from root dir. However looks like you need to copy package.json from ClientApp dir

Two way to fix this: 1) Change compose file context: ./ClientApp/ 2) Change docker file COPY ./ClientApp/package.json /app/package.json

I think better to change docker file because in feature you may want to copy some file from root dir

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.