0

For example.

Every time I build.

  • Copy package.json
  • Install package.json
  • Add current directory.

My question is:

Why it does not use from the cache. For example, It should not install the package.json from the start if the package.json does not change.

It should use the cache and update only the changes code.

Update:

Dockerfile

FROM ubuntu:18.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

RUN apt-get update && apt-get upgrade -y \
    && apt-get install -y  --no-install-recommends \
    build-essential \
    ca-certificates \
    gcc \
    git \
    libpq-dev \
    make \
    python-pip \
    python2.7 \
    python2.7-dev \
    apt-transport-https \
    curl \
    g++ \
    sudo \
    wget \
    bzip2 \
    chrpath \
    libssl-dev \
    libxft-dev \
    libfreetype6 \
    libfreetype6-dev \
    libfontconfig1 \
    libfontconfig1-dev \
    libfontconfig \
    poppler-utils \
    imagemagick \
    && apt-get clean \
    && rm -rf /tmp/* /var/lib/apt/lists/* \
    && apt-get -y autoclean

RUN apt-get update && apt-get install -y  --no-install-recommends software-properties-common && add-apt-repository ppa:malteworld/ppa && apt update && apt install -y  --no-install-recommends pdftk \
    && apt-get clean \
    && rm -rf /tmp/* /var/lib/apt/lists/* \
    && apt-get -y autoclean


ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 10.6.0

# Install nvm with node and npm
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash \
    && source $NVM_DIR/nvm.sh \
    && nvm install $NODE_VERSION \
    && nvm alias default $NODE_VERSION \
    && nvm use default

# Set up our PATH correctly so we don't have to long-reference npm, node, &c.
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

# Set the work directory
RUN mkdir -p /var/www/app/jobsaf-website
RUN mkdir /data
RUN mkdir /data/db

WORKDIR /var/www/app/jobsaf-website

RUN npm install -g node-gyp @angular/[email protected] nodemon  request


# Add our package.json and install *before* adding our application files
COPY package.json ./

# RUN npm install --force
RUN npm install --force

RUN npm rebuild node-sass


# Add application files
ADD . .

EXPOSE 3000 5858 4200 35729 27017 6379 49153

.dockerignore

# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/tmp
/public/__build__/
/src/*/__build__/
/__build__/**
/public/dist/
/src/*/dist/
/dist/**
/.awcache
.webpack.json
/compiled/
dll/

package-lock.json
# dependencies
/node_modules
*/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
**.js.map
.settings/

# IDE - VSCode
.vscode/


# misc
/.sass-cache
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
testem.log
/typings

# e2e
/e2e/*.js
/e2e/*.map

#System Files
.DS_Store
Thumbs.db

*.csv
*.dat
*.iml
*.log
*.out
*.pid
*.seed
*.sublime-*
*.swo
*.swp
*.tgz
*.xml
.strong-pm
coverage

npm-debug*
/admin/dist

npm
/.cache-loader/*
stats.json

!/src/assets/js/admin-header.js
!/src/assets/js/website-custom.js

webpack-cache/
web/

/src/app/**/*.map
/src/app/**/*.js

4
  • Can you show us your code and how you are doing the build and what is the output of that build ? Commented Feb 24, 2019 at 7:47
  • It sounds correct, maybe there is some other instruction before that causes a cache invalidation , and you have to know that when a layer is rebuilt, all other following do the same. Can you show your Dockerfile and.Dockerignore? Commented Feb 24, 2019 at 8:22
  • I have added Dockerfile and .dockerignore Commented Feb 24, 2019 at 9:02
  • @MostafaHussein Commented Feb 24, 2019 at 10:06

1 Answer 1

1

--force should be removed from the following line as it will ignore any cache and do a fresh installation for your packages which leads to a new docker build layer starting from the installation step.

RUN npm install --force

The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk.

Sign up to request clarification or add additional context in comments.

1 Comment

I will check and back to you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.