![]() ![]() This instructs Docker to cache the first COPY and RUN commands when package.json is not touched. In order to make use of caching process of Docker, you can segment your configuration as follows: WORKDIR /usr/app Your application is very basic, but think of a big applications where "npm install" should take several minutes. It is a good practice to segment a bit your configuration so that when you make a change for example in your index.js (so then you need to rebuild your image), you will not need to run "npm install" while the package.json has not been modified. Now the good reason to use WORKDIR instruction is that you avoid mixing your application files and directories with the root file system of the container (to avoid overriding file system directories in case you have similar directories labels on your application directories) (container directory which is now /usr/app thanks to the WORKDIR instruction)" instead of "COPY. Here is how you can complete this: WORKDIR /usr/app You should specify the WORKDIR prior to COPY instruction in order to ensure the execution of npm install inside the directory where all your application files are there. This error may trigger if the CI software you're using like semantic-release is built in node and you attempt to install it outside of a working directory. In the event you're wanting to install a package globally outside of working directory with a package.json, you should use the -g flag. I suggest using this Dockerfile: FROM node:alpine usr/app) does not find the package.json. usr/app/usr/app.Īs a result CMD, which is followed where specified by WORKDIR (. usr/app as this produces the following structure in the container. ![]() usr/app it is wrong to ask to copy from. WORKDIR specifies the context to the COPY that follows it. The correct answer is basically right, but when I tried it still didn't work. Use the following Dockerfile: # Specify a base image Executing the npm install in a project directory of the container specified by WORKDIR resolves the issue. When no WORKDIR is specified, npm install is executed in the root directory of the container, which is resulting in this error. This issue is happening due to changes in NodeJS starting with version 15. ![]()
0 Comments
Leave a Reply. |