#Problem with docker - can't find package.json

14 messages · Page 1 of 1 (latest)

vapid bloom
#

Hi,
I have a problem that I don't understand fully. I have a folder with docker-compose and Dockerfile. Container is being built, but I have error that npm can't find file or directory with package.json. When I'm mobing these 2 files to main root it's working like a charm. So probably there is a mistake in docker-compose or Dockerfile. Could someone advise me something, please.

app structure:
app
--docker-compose
----docker-compose.yml
----Dockerfile
--package.json
--...

services:
  dev:
    container_name: animals_api_dev
    image: animals-api-dev:1.0.0
    build:
      context: ../
      target: development
      dockerfile: ./docker-compose/Dockerfile
    command: npm run start:debug
    ports:
      - ${SERVER_PORT}:${SERVER_PORT}
    environment:
      - MONGO_HOST=${MONGO_HOST}
      - MONGO_PORT=${MONGO_PORT}
      - MONGO_USERNAME=${MONGO_USERNAME}
      - MONGO_PASSWORD=${MONGO_PASSWORD}
    networks:
      - animals-api-network
    depends_on:
      - mongo-database
      - mongo-express
      - redis
    volumes:
      - .:/usr/src/app
    restart: unless-stopped

networks:
  animals-api-network:
    driver: bridge

Dockerfile:

FROM node:18-alpine As development

WORKDIR /usr/src/app

COPY --chown=node:node package*.json ./

RUN npm ci

COPY --chown=node:node . .

USER node
tulip yew
#

your dockerfile is below the . directory zoopthedoop

#

Your context should start at or above the parent.

vapid bloom
tulip yew
#

COPY should be located within the Dockerfile directory and not outside (eg. parent).

#

The build actually happens in /tmp/docker-12345, so a relative path like ../relative-add/some-file is relative to /tmp/docker-12345. It would thus search for /tmp/relative-add/some-file

#

Specifically:

#

COPY obeys the following rules:

The <src> path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

vapid bloom
#

Thnaks for it. I know what is the problem, but still I don't know what to change in Dockerfile 😦

tulip yew
#

You don't change the dockerfile.

#

You move the docker file.

#

./Dockerfile
./<files>

#

Needs to be at the same level or below.