title: Why docker-compose build start from begining
body: <p>For example.</p>
  
  <p>Every time I build.</p>
  
  <ul>
  <li>Copy package.json</li>
  <li>Install package.json</li>
  <li>Add current directory.</li>
  </ul>
  
  <p>My question is:</p>
  
  <p>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.</p>
  
  <p>It should use the cache and update only the changes code.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p><code>Dockerfile</code></p>
  
  <pre><code>FROM ubuntu:18.04
  RUN rm /bin/sh &amp;&amp; ln -s /bin/bash /bin/sh
  
  RUN apt-get update &amp;&amp; apt-get upgrade -y \
      &amp;&amp; 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 \
      &amp;&amp; apt-get clean \
      &amp;&amp; rm -rf /tmp/* /var/lib/apt/lists/* \
      &amp;&amp; apt-get -y autoclean
  
  RUN apt-get update &amp;&amp; apt-get install -y  --no-install-recommends software-properties-common &amp;&amp; add-apt-repository ppa:malteworld/ppa &amp;&amp; apt update &amp;&amp; apt install -y  --no-install-recommends pdftk \
      &amp;&amp; apt-get clean \
      &amp;&amp; rm -rf /tmp/* /var/lib/apt/lists/* \
      &amp;&amp; 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 \
      &amp;&amp; source $NVM_DIR/nvm.sh \
      &amp;&amp; nvm install $NODE_VERSION \
      &amp;&amp; nvm alias default $NODE_VERSION \
      &amp;&amp; nvm use default
  
  # Set up our PATH correctly so we don't have to long-reference npm, node, &amp;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/cli@6.2.3 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
  </code></pre>
  
  <p><code>.dockerignore</code></p>
  
  <pre><code># 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
  
  </code></pre>