Creating a Dockerfile – docker starts from scratch on each new build

I am trying to build a dockerfile – iteratively adding lines and testing. My understanding was that docker will cache the lines that have already been built and start from the new lines I had added. The case seems to be that it just builds from scratch each time I call build on my container. Is this normal? If not – what am I doing wrong?

  • how does Spark limit the usage of cpu cores and memory?
  • Is it possible to expose http ports with docker-compose?
  • Getting docker stats programmatically
  • Install Oracle on docker centos container: Insufficient disk space
  • What is the best way to append to /etc/hosts within Dockerfile
  • Installing custom modules into docker container
  • Docker container with Neo4j 2.3 enterprise edition exits without error message when mounting graph.db volume
  • HAproxy: dynamic count of hosts for scalability
  • how to add localhost port to docker container
  • In docker run --ulimit cpu=10 does not work in some cases
  • What's the difference between RUN and CMD in a docker file and when should I use one or the other?
  • how to connect Docker containers without a bridge?
  • 2 Solutions collect form web for “Creating a Dockerfile – docker starts from scratch on each new build”

    As demas said, if you’re simply appending lines, the previous lines will be cached.

    However, if anywhere in your Dockerfile you have a line like

    ADD . /some/path

    then Docker will assume that that line has changed even if it was only the Dockerfile that changed. So that line and anything after it will never be cached, unless nothing in the folder you’re adding has changed.

    You should be able to see whether this is happening by paying close attention to the output of the docker build command.

    As a side note: a consequence of this is that if you’re building a Dockerfile, you generally want to add the files in the directory as late as possible, doing any preparations beforehand. Of course, you will end up having to do things to your files (like some kind of build process) which is unfortunately hard to cache.

    If I understood correctly you can look at Docker as version control system where each line in your Dockerfile is a commit to the container.

    If you add new line to your Dockerfile, Docker get the last revision of container and make a new commit. If you add line on the middle of your Dockerfile, Docker get one of the previous revisions and make new commit to this part of the tree.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.