title: Is there a way to add only changed files to a docker image as a new layer - without resorting to docker commit?
body: <p><strong>TL;DR</strong></p>
  
  <p>Running <code>COPY . /app</code> on top of an image with but slightly outdated source code creates a new layer as large as the whole source code, even when there is only a few bytes worth of changes.
  Is there a way to add only changed files to this docker image as a new layer - without resorting to docker commit?</p>
  
  <p><strong>Long version:</strong></p>
  
  <p>When deploying our application to production, we need to add the source code to the image. A very simple Dockerfile is used for this:</p>
  
  <pre><code>FROM neam/dna-project-base-debian-php:0.6.0
  COPY . /app
  </code></pre>
  
  <p>Since the source code is huge (1.2 GB), this makes for quite a hefty push upon each deploy:</p>
  
  <pre><code>$ docker build -f .stack.php.Dockerfile -t project/project-web-src-php:git-commit-17c279b .
  Sending build context to Docker daemon 1.254 GB
  Step 0 : FROM neam/dna-project-base-debian-php:0.6.0
   ---&gt; 299c10c416fc
  Step 1 : COPY . /app
   ---&gt; 78a30802804a
  Removing intermediate container 13b49c323bb6
  Successfully built 78a30802804a
  
  $ docker tag -f project/project-web-src-php:git-commit-17c279b tutum.co/project/project-web-src-php:git-commit-17c279b
  $ docker login --email=tutum-project@project.com --username=project --password=******** https://tutum.co/v1
  WARNING: login credentials saved in /home/dokku/.docker/config.json
  Login Succeeded
  $ docker push tutum.co/project/project-web-src-php:git-commit-17c279b
  The push refers to a repository [tutum.co/project/project-web-src-php] (len: 1)
  Sending image list
  Pushing repository tutum.co/project/project-web-src-php (1 tags)
  Image a604b236bcde already pushed, skipping
  Image 1565e86129b8 already pushed, skipping
  ...
  Image 71156b357f2f already pushed, skipping
  Image 299c10c416fc already pushed, skipping
  78a30802804a: Pushing [=========&gt;                     ] 234.2 MB/1.254 GB
  </code></pre>
  
  <p>Upon the next deploy, we only want to add the changed files to the image, but watch and behold when running <code>COPY . /app</code> on top of the previously added image actually requires us to push 1.2 GB worth of source code AGAIN, even when we only change a few bytes worth of source code:</p>
  
  <p>New Dockerfile (<code>.stack.php.git-commit-17c279b.Dockerfile</code>):</p>
  
  <pre><code>FROM project/project-web-src-php:git-commit-17c279b
  COPY . /app
  </code></pre>
  
  <p>After change a few files, adding some text and code, then building and pushing:</p>
  
  <pre><code>$ docker build -f .stack.php.git-commit-17c279b.Dockerfile -t project/project-web-src-php:git-commit-17c279b-with-a-few-changes .
  Sending build context to Docker daemon 1.225 GB
  Step 0 : FROM project/project-web-src-php:git-commit-17c279b
   ---&gt; 4dc643a45de3
  Step 1 : COPY . /app
   ---&gt; ecc7adc194c4
  Removing intermediate container cb3e87c6cb7a
  Successfully built ecc7adc194c4
  $ docker tag -f project/project-web-src-php:git-commit-17c279b-with-a-few-changes tutum.co/project/project-web-src-php:git-commit-17c279b-with-a-few-changes
  $ docker push tutum.co/project/project-web-src-php:git-commit-17c279b-with-a-few-changes
  The push refers to a repository [tutum.co/project/project-web-src-php] (len: 1)
  Sending image list
  Pushing repository tutum.co/project/project-web-src-php (1 tags)
  Image 1565e86129b8 already pushed, skipping
  Image a604b236bcde already pushed, skipping
  ...
  Image fe64bff23cf8 already pushed, skipping
  Image 71156b357f2f already pushed, skipping
  ecc7adc194c4: Pushing [==&gt;                           ] 68.21 MB/1.225 GB
  </code></pre>
  
  <p>There is a workaround to achieve small layers as described on <a href="https://stackoverflow.com/questions/26014503/updating-docker-images-with-small-changes-using-commits">Updating docker images with small changes using commits</a> which includes launching a rsync process within the image and then using docker commit to save the new contents as a new layer, however (as mentioned in that thread) this is unorthodox since the image is not built from a Dockerfile, and we prefer an orthodox solution that does not rely on docker commit.</p>
  
  <p>Is there a way to add only changed files to this docker image as a new layer - without resorting to docker commit?</p>
  
  <p>Docker version 1.8.3</p>