Docker does not cache npm install

I can't seem to make the docker file cache with my npm install. I configured it like all examples and the package.json doesn't change, but it still downloads all dependencies.

That's what i am

FROM mf/nodebox

# Maintainer
MAINTAINER Raif Harik <reharik@gmail.com>

RUN rm /bin/sh && ln -s /bin/bash /bin/sh

ADD /app/package.json /tmp/package.json
RUN cd /tmp && npm install && npm install -g babel
RUN cd /tmp && cp -a /tmp/node_modules /opt/app/current/node_modules

# Entrypoint to docker shell
ENTRYPOINT ["docker-shell"]

#this is the flag that tells the docker-shell what mode to execute
# Startup commands
CMD ["-r"]

# set WORKDIR
WORKDIR /opt/app/current

# Add shell script for starting container
ADD ./docker-shell.sh /usr/bin/docker-shell
RUN chmod +x /usr/bin/docker-shell

COPY /app /opt/app/current

      

Then the output I get is

Building domain...
Step 0 : FROM mf/nodebox
 ---> 4ee7c51a410d
Step 1 : MAINTAINER Raif Harik <reharik@gmail.com>
 ---> Using cache
 ---> 78d0db67240c
Step 2 : RUN rm /bin/sh && ln -s /bin/bash /bin/sh
 ---> Using cache
 ---> d7d360d8f89a
Step 3 : ADD /app/package.json /tmp/package.json
 ---> 5b373dae5141
Removing intermediate container f037272f49c3
Step 4 : RUN cd /tmp && npm install && npm install -g babel
 ---> Running in cb89bb6fc2d0
npm WARN package.json MF_Domain@0.0.1 No description

      

So, it caches the commands of the first pair, but in step 3 it ends up with package.json and then goes to npm for step 4.

Edit:

I think I should mention that when I deploy a new change in the code (or for my experiment with this problem, just the same code) while the package.json remains the same, it gets copied to the deployment folder. I don't know if docker is checking the generated date, checksum, or doing a diff. If it's a generated date, there might be a problem.

+3


source to share


1 answer


from docker's documentation it says that

In the case of instructions ADD

and COPY

the contents of the file (s) placed in the image is checked. Specifically, a checksum is performed on the file (s), and then that checksum is used during a cache lookup. If something has changed in the file (s) , including its metadata , then the cache is invalid.

This metadata includes the time the file was modified.



There are tricks to get around this (for example, docker add cache on git to the same file ).

See also the discussion on the Docker github project.

+1


source







All Articles