Ho cercato per qualche tempo di memorizzare i node_modules
in una build di Docker. Ho provato diversi approcci, incluso quello qui , ma senza successo.
La mia ragione principale per la cache è perché ci vogliono 30 + minuti per build la mia image, che è troppo.
Il mio Dockerfile
:
# This image will be based on the oficial nodejs docker image FROM node:4.2.1 RUN npm install -g [email protected] && \ npm install -g gulp && \ npm install -g tsd # Use changes to package.json to force Docker not to use the cache # when we change our application's nodejs dependencies: ADD package.json /src/package.json RUN cd /src && npm install # Put all our code inside that directory that lives in the container ADD . /src # Set in what directory commands will run WORKDIR /src # Install dependencies RUN cd /src && \ tsd reinstall -so && \ jspm install && \ gulp build -p # Tell Docker we are going to use this port EXPOSE 3000 # The command to run our app when the container is run CMD ["npm", "run", "start-production"]
Non ho un file .dockerignore
. Ho aggiunto uno prima, ma non ho ancora memorizzato i miei node_modules
.
Quindi, come memorizzare i miei nodes_moduli ? Sentitevi liberi di suggerire modifiche al Dockerfile
.
Grazie!
Non sono sicuro se è la radice dell'errore, ma cercare di specificare la cartella di destinazione nel command ADD e non il file di destinazione.
ADD package.json /src
Inoltre, è ansible utilizzare COPIA invece di ADD ( ADD può lavorare con url e archivi, ma non è necessario qui).
È inoltre ansible specificare la directory di lavoro in precedenza nel file.
Provare con questo codice:
# This image will be based on the oficial nodejs docker image FROM node:4.2.1 RUN npm install -g [email protected] && \ npm install -g gulp && \ npm install -g tsd # Set in what directory commands will run WORKDIR /src # Use changes to package.json to force Docker not to use the cache # when we change our application's nodejs dependencies: COPY package.json ./ RUN npm install # Put all our code inside that directory that lives in the container COPY . ./ # Install dependencies RUN tsd reinstall -so && \ jspm install && \ gulp build -p # Tell Docker we are going to use this port EXPOSE 3000 # The command to run our app when the container is run CMD ["npm", "run", "start-production"]