Is there any way to "apply a patch" to a docker image, particularly one or more RUN
, ADD
, etc. commands?
For example a RUN
command might take 20 minutes to run, that downloads, compiles, and installs a binary. Is it possible to take a diff of that and apply it to another image?
The only way I can think of (which I haven't attempted yet) is to run docker diff
, parse the output, create a tgz, then use the tgz as an ADD
in another Dockerfile
.
I understand that there are issues with this, e.g. if an apt-get update
is called beforehand which might break an expected dynamic library linkage for the binary, etc. I'm OK with this as my tests will fail, and will show that I have to rebuild the "diff" again.
I also realise there could be conflicts. I'm happy to replace the file completely.
The reason for this functionality is to save time. For example sometimes early Dockerfile
commands need to be changed, and will break the cache. Also, as much as I try to make them identical to take advantage of cache, it is not always possible for the preceding commands in two different Dockerfiles to be the same.
The short answer is that no, you can't do that.
The long answer is that with sufficient motivation you might be able to write code that would do what you want. I've written some documentation on the docker image format (and a tool for manipulating those images) here:
That might give you some ideas about where to start.
Personally, I suspect the effort is not worth it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With