Docker updating image along when dockerfile changes

Docker

Docker Problem Overview


I'm playing with docker by creating a Dockerfile with some nodejs instructions. Right now, every time I make changes to the dockerfile I recreate the image by running sudo docker build -t nodejstest . in my project folder however, this creates a new image each time and swallows my ssd pretty soon.

Is there a way I can update an existing image when I change the dockerfile or I'm forced to create a new one each time I make changes to the file?

Sorry if it's a dumb question

Docker Solutions


Solution 1 - Docker

Docker build support caching as long as there is no ADD instruction. If you are actively developing and changing files, only what is after the ADD will be rebuilt.

Since 0.6.2 (scheduled today), you can do docker build --rm . and it will remove the temporary containers. It will keep the images though.

In order to remove the orphan images, you can check them out with docker images, and perform a docker rmi <id> on one of them. As of now, there is an auto-prune and all untagged images (orphans, previous builds) will be removed.

Solution 2 - Docker

According to this best practices guide if you keep the first lines of your dockerfile the same it'll also cache them and reuse the same images for future builds

Solution 3 - Docker

During development, it makes less sense to re-build a whole container for every commit. Later, you can automate building a Docker container with your latest code as part of your QA/deployment process.

Basically, you can choose to make a minimal container that pulls in code (using git when starting the container, or using -v /home/myuser/mynode:/home/myuser/mynode with ENTRYPOINT to run node).

See my answer to this question:

https://stackoverflow.com/questions/18806179/docker-rails-app-and-git/18816278#18816278

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRomeo MihalceaView Question on Stackoverflow
Solution 1 - DockercreackView Answer on Stackoverflow
Solution 2 - DockerReza SView Answer on Stackoverflow
Solution 3 - DockerBraveNewCurrencyView Answer on Stackoverflow