How to change Docker config of an already running container? How to change Docker config of an already running container? docker docker

How to change Docker config of an already running container?


You need to make your modified config files visible inside the container.

If they are built into the image (possibly via COPY or ADD in the Dockerfile), then restarting your container does not help, because you're doing it on an old image. You should be rebuilding the image, stopping the old one and starting the new. Rather annoying and error-prone way.

Better way is to "mount" your files via volumes. Docker volumes can be single files, not only directories. You can add the section volumes in your docker-compose.yml:

my_container:  image: my_image  volumes:    sentry.conf.py:/full/path/to/sentry.conf.py/in/the/container    config.yml:/similar/full/path/to/config.yml  ports:    ...  command: ...

There's a chance you already have some volumes defined for this particular container (to hold persistent data for example), then you need to simply add volume mappings for your config files.

Hope this helps. All the best in the New Year!


This is how you can edit an existing docker container config:

  1. stop container:

    docker stop <container name>

  2. edit config:

    docker run -it -v /var/lib/docker:/var/lib/docker alpine vi $(docker inspect --format='/var/lib/docker/containers/{{.Id}}/config.v2.json' <container name>)

  3. restart docker


if the configuration files are stored as docker configs, then I found this guide to work...

https://medium.com/@lucjuggery/about-using-docker-config-e967d4a74b83

  • Basically add update as a NEW config
  • tell service to remove the old and then add the new config as the one to use. Service will be restarted
  • now you can remove the old docker config

this is not very nice, and if you want to name the new config with the old config identifier, you have to repeat it again!

Arrggghhh....