5

docker inspect returns all sorts of interesting information about a docker image or container (or another object).

Where is this information stored? Is it possible to edit it?

1
  • Depending on what you're trying to achieve, you may be best off setting a label.
    – BMitch
    Dec 4, 2016 at 20:33

3 Answers 3

2

No it's not possible to edit the 'built in' configuration and state information returned by docker inspect. However if you want to add information to docker inspect then you can look into adding labels to your images / containers and then introspecting that (as label information is returned by docker inspect).

Official docs on Labelling (various different objects) can be found here.

6

一. Manual modification

as johnharris85 says.
until now (17.12) docker no api to edit container's most options.

the only thing we can do is edit config files on disk:


generally, the config was in folder /var/lib/docker/containers/<conainerID>*/

  • config.v2.json
  • hostconfig.json

edit them, restart docker service, new config will load.

// tested in docker 17.12

see also: https://stackoverflow.com/a/49371983/4896468


二. about Synology NAS docker

Recently I realized the docker cmd in Synology NAS DSM system has ability to edit container setttings via cmdline or webgui (without re-create it, or fully restat docker service)

the cmdline

here is the docker update diff:

  • docker 20.10.3 from DSM 6.2
  • docker 19.03.6 from ubuntu 18.04
$ docker update --help
 
 Usage:  docker update [OPTIONS] CONTAINER [CONTAINER...]
 
 Update configuration of one or more containers
 
 Options:
       --blkio-weight uint16        Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
+      --cap-add list               Add Linux capabilities
+      --cap-drop list              Drop Linux capabilities
       --cpu-period int             Limit CPU CFS (Completely Fair Scheduler) period
       --cpu-quota int              Limit CPU CFS (Completely Fair Scheduler) quota
       --cpu-rt-period int          Limit the CPU real-time period in microseconds
       --cpu-rt-runtime int         Limit the CPU real-time runtime in microseconds
   -c, --cpu-shares int             CPU shares (relative weight)
       --cpus decimal               Number of CPUs
       --cpuset-cpus string         CPUs in which to allow execution (0-3, 0,1)
       --cpuset-mems string         MEMs in which to allow execution (0-3, 0,1)
+  -e, --env list                   Set environment variables
+      --env-file list              Read in a file of environment variables
       --kernel-memory bytes        Kernel memory limit
+      --link list                  Add link to another container
   -m, --memory bytes               Memory limit
       --memory-reservation bytes   Memory soft limit
       --memory-swap bytes          Swap limit equal to memory plus swap: '-1' to enable unlimited swap
       --pids-limit int             Tune container pids limit (set -1 for unlimited)
+      --privileged                 Give extended privileges to this container
+  -p, --publish list               Publish a container's port(s) to the host
       --restart string             Restart policy to apply when a container exits
+  -v, --volume list                Bind mount a volume

the WebGUI

DSM_docker_edit.png


--

I'm not sure where to get this enhanced version docker.
wish someday this can be implemented in offical version.

1
  • 3
    It's very important to restart docker service sudo systemctl restart docker immediately after editing config.v2.json. Otherwise, docker commands will overwrite your changes to config.v2.json.
    – wisbucky
    Jul 26, 2020 at 21:55
1

Yes, @johnharris points out there is no direct editing api

@yurenchen is correct that editing /var/lib/docker/containers/<containerID>/hostconfig.json then restarting the docker daemon will update the output of docker inpect <containerID>

During a docker update, the default runtime changed from oci to runc and I was unable to restart a stack of containers. Output from sudo cat /var/lib/docker/<containerID>/hostconfig.json | jq .Runtime was "oci" but needed to be "runc" after update.

Manually started sudo docker start <short_containerID>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.