Skip to main content

edit docker image metadata (including remove docker volume settings)

Project description

PyPI downloads

edit docker image metadata

The initial motiviation for the creation of the tool came from the fact that it is not possible to remove VOLUME entries in an image. You can basically change a USER or WORKDIR setting but you can only ever add VOLUME and PORT entries.

The wish to REMOVE ALL VOLUMES came from the fact that I did want to download a tested image for local tests where the data part should be committed to the history as well in order to turn back both program and data to a defined state so that another test run will start off the exact same checkpoint.

While docker does not allow to edit the metadata of an image directly, there is a workaround - one may "docker save" an image into an archive file that contains all the layers and metadata json files. After modifying the content one can "docker load" the result back with the history being preserved.

Correcting some images from other sources became such a regular task that I started to fill in a python script to help with the daily work. In order to allow coworkers to understand what was intended, the input syntax is somewhat descriptive (likeSQL).

 ./docker-copyedit.py \
 FROM image1 INTO image2 REMOVE ALL VOLUMES
     
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     add volume /var/tmp
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     REMOVE VOLUME /var/atlassian/jira-data
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     REMOVE VOLUMES '/var/*' AND RM PORTS 80%0
 
 ./docker-copyedit.py \
     into image2 from image1 set no user
 ./docker-copyedit.py \
     set null user and set null cmd from image1 into image2
 ./docker-copyedit.py FROM image1 INTO image2 \
     set null user + set null cmd + rm all volumes

 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     set null entrypoint and set cmd /entrypoint.sh
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     set shell cmd "/entrypoint.sh foo"
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     set label author "real me" and rm labels old%
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     set env MAINDIR "/path" and rm env backupdir

 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     REMOVE PORT 4444
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     remove port ldap and rm port ldaps
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     remove all ports
 ./docker-copyedit.py FROM image1 INTO image2 -vv \
     add port ldap and add port ldaps

Of course you may have image1 and image2 to be the same tag name but remember that the image hash value will change while copyediting the image archive on the disk. You will be left with a dangling old (untagged) image.

Other than 'entrypoint','cmd' and 'user' you can also set the string values for 'workdir'/'workingdir', 'domainname', 'hostname', 'arch'/'architecture' and 'author' in configs. The values in the env list and label list can be modified too. Healthcheck can be removed. If the edit command did not really change something then the edited image is not loaded back from disk. Instead the old image is possibly just tagged with the new name.

For podman it is not possible to check service user examples and healthcheck examples as it seems to be not supported. You can globally override the docker tool with --docker=podman, or switch to the alternative tool with PODMAN image1 INTO image2. Using the special FROM image1 IMPORT image2 commands you can transfer images between the local storage spaces.

By default the tool will use a local "load.tmp" temporary directory. You may set "-T $TMPDIR" explicitly to have it run in a normal temporary directory - but be aware that the archive files during save/load can be quite big and the tool will even unpack the archives temporarily. That's why the "-T tmpdir" should point to a space that is hopefully big enough (like the build server workspace you are already in).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker-copyedit-1.4.7321.tar.gz (27.6 kB view details)

Uploaded Source

File details

Details for the file docker-copyedit-1.4.7321.tar.gz.

File metadata

  • Download URL: docker-copyedit-1.4.7321.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.15

File hashes

Hashes for docker-copyedit-1.4.7321.tar.gz
Algorithm Hash digest
SHA256 572fbbaa1df6104b499ca37d02d79f23ef5a2f60b8f6c2ef6b41ed53bc355808
MD5 9dca15ceacb1942f265ec72b397f91d3
BLAKE2b-256 5c36a0bba205ca21d3fc1b438c398c32da01f74a1dc4335f4690a0fa27c3a9e3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page