Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I edit an existing docker image metadata?

I would like to edit a docker images metadata for the following reasons:

  • I don't like an image parents EXPOSE, VOLUME etc declaration (see #3465, Docker-Team did not want to provide a solution), so I'd like to "un-volume" or "un-expose" the image.

  • I dont't like an image ContainerConfig (see docker inspect [image]) cause it was generated from a running container using docker commit [container]

  • Fix error durring docker build or docker run like:
    cannot mount volume over existing file, file exists [path]

Is there any way I can do that?

like image 772
GameScripting Avatar asked Feb 18 '17 14:02

GameScripting


2 Answers

Its a bit hacky, but works:

  1. Save the image to a tar.gz file:
    $ docker save [image] > [targetfile.tar.gz]

  2. Extract the tar file to get access to the raw image data:
    tar -xvzf [targetfile.tar.gz]

  3. Lookup the image metadata file in the manifest.json file: There should be a key like .Config which contains a [HEX] number. There should be an exact [HEX].json in the root of the extracted folder.
    This is the file containing the image metadata. Edit as you like.

  4. Pack the extracted files back into an new.tar.gz-archive

  5. Use cat [new.tar.gz] | docker load to re-import the modified image

  6. Use docker inspect [image] to verify your metadata changes have been applied

EDIT: This has been wrapped into a handy script: https://github.com/gdraheim/docker-copyedit

like image 124
GameScripting Avatar answered Sep 27 '22 16:09

GameScripting


I had come across the same workaround - since I have to edit the metadata of some images quite often (fixing an automated image rebuild from a third party), I have create a little script to help with the steps of save/unpack/edit/load.

Have a look at docker-copyedit. It can remove or overrides volumes as well as set other metadata values like entrypoint and cmd.

like image 31
Guido U. Draheim Avatar answered Sep 27 '22 16:09

Guido U. Draheim