Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

Solving the error of "docker build" not accesing package.json

I am trying to build an image for an express app and I have issues running the command. The error indicates that the package.json file is not accessible. Please look at the structure error below.

Sending build context to Docker daemon  2.048kB
Step 1/7 : FROM node:8-alpine
 ---> 2b8fcdc6230a
Step 2/7 : WORKDIR /usr/src/app
 ---> Using cache
 ---> d0f2d783ba5a
Step 3/7 : COPY package*.json ./
COPY failed: no source files were specified

Also, the docker file is shown below:

FROM node:8-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]

Then lastly the file structure is shown below:

This the file structure in my VSCode

I'd like any assistance possible. Thanks.

question from:https://stackoverflow.com/questions/65844113/solving-the-error-of-docker-build-not-accesing-package-json

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This could be due to the Node.JS version you are trying to use in the docker file, i'm not entirely sure if this is the case but I have used this docker file with my node.js express application and it seemed to work. Give it a shot.

FROM node:12
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...