Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to "apply a patch" to a docker image?

Tags:

docker

diff

patch

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.

like image 582
gak Avatar asked Oct 31 '22 08:10

gak


1 Answers

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:

  • http://blog.oddbit.com/2015/02/13/unpacking-docker-images/

That might give you some ideas about where to start.

Personally, I suspect the effort is not worth it.

like image 158
larsks Avatar answered Nov 15 '22 07:11

larsks