-2

I am making a react js project and i am using docker. as the ubuntu restart all the dependencies start download again. i am not able to understand why dependencies not saving in the project folder. I don't want that every time my dependencies download again and again on restart.

Pull everytime on database:start in docker

latest: Pulling from library/mysql

aa18ad1a0d33: Pull complete fdb8d83dece3: Pull complete 75b6ce7b50d3: Pull complete ed1d0a3a64e4: Pull complete 8eb36a82c85b: Pull complete 41be6f1a1c40: Pull complete 0e1b414eac71: Pull complete 914c28654a91: Pull complete 587693eb988c: Pull complete b183c3585729: Pull complete 315e21657aa4: Pull complete

Digest: sha256:0dc3dacb751ef46a6647234abdec2d47400f0

Rover
  • 661
  • 2
  • 18
  • 39

1 Answers1

1

Docker has a way to store things in cache: It checks for modifications in each lines of instruction of the Dockerfile and when it finds a difference at a line it re-runs it and all the instructions below. For the COPY instruction it works the same except it also checks if the files themselves have changed.
I assume that you are copying your project files before installing your dependencies in your Dockerfile.
You should instead copy your package.json first, then install the dependencies, then copy all your project's files. That way it will download new dependencies only if your package.json file changed.
Here is an example of what I mean:

FROM node:latest
COPY package.json .
RUN npm install
COPY . .
EXEC npm run
Leogout
  • 1,187
  • 1
  • 13
  • 32
  • I'm sorry but I think I can't understand your question. Have a nice day. – Leogout Oct 31 '19 at 07:43
  • okay. but as i updated above you can check. yarn database:start pull mysql library, every time as i shutdown and start ubuntu. but i want that mysql install one time and save in the system and don't download again and again from online. – Rover Oct 31 '19 at 07:46