skip to Main Content

File Directory
Image

Dockerfile

FROM node:16

WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

ENV PORT=5000

EXPOSE 5000

CMD [ "npm", "run", "dev" ]

running docker file locally

    Login Succeeded
$ docker build -t $CI_DOCKER_REPO:$CI_COMMIT_SHORT_SHA -f ./cronTest/Dockerfile .
Step 1/9 : FROM node:16
 ---> e90654c39524
Step 2/9 : WORKDIR /app
 ---> Using cache
 ---> 4ffb8744c0c4
Step 3/9 : RUN ls
 ---> Running in 992c3cd680f3
Removing intermediate container 992c3cd680f3
 ---> 0124eea0f9e9
Step 4/9 : COPY package.json ./
COPY failed: file not found in build context or excluded by .dockerignore: stat package.json: file does not exist
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

Even though the same file is used can anyone check this if something is wrong with my dockerfile

2

Answers


  1. update to the following, but can’t help much further without full context of structure

    COPY ./package.json ./

    Login or Signup to reply.
  2. The local build and the pipeline build are launching from different paths, but both are provided with the same . relative build context, which means they resolve to different paths.

    To emulate the local build, supply the equivalent "build context" paramater

    docker build -t $CI_DOCKER_REPO:$CI_COMMIT_SHORT_SHA 
      -f ./cronTest/Dockerfile 
      ./crontTest
    

    Or move into the same directory

    cd cronTest
    docker build -t $CI_DOCKER_REPO:$CI_COMMIT_SHORT_SHA 
      -f Dockerfile 
      .
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search