Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply new log configuration to all containers after daemon restart

Tags:

docker

Is there any way the new configuration in daemon.json to apply to all the containers after the daemon restarts?

Docker seems to not apply log configuration changes in daemon.json to already running containers, even if the daemon is restarted:

  1. Run a container (c1) with some log configuration in daemon.json like ... "max-file": "3" ...
  2. docker inspect c1 shows the configuration
  3. Change the daemon.json to ... "max-file": "5" ...
  4. Restart the daemon with service docker restart
  5. docker inspect c1 shows the old configuration
  6. If I run a new container (c2) and docker inspect c2 the new config applies to this one

I wouldn't expect this behaviour.

like image 372
AitorF Avatar asked Sep 20 '25 07:09

AitorF


1 Answers

Not what you wanted to hear, but...

That behavior is to be expected. Containers are static from the point of creation in their configuration.

To underline this statement, here is an example with a storage driver. If you choose another storage driver your current containers won't work anymore. You can find this particular info here:

https://docs.docker.com/v17.09/engine/userguide/storagedriver/selectadriver/#shared-storage-systems-and-the-storage-driver

Important: When you change the storage driver, any existing images and containers become inaccessible. This is because their layers cannot be used by the new storage driver. If you revert your changes, you will be able to access the old images and containers again, but any that you pulled or created using the new driver will then be inaccessible.


To role out the changes that you have done in your deamon you need to recreate all containers on the system.

Save your data

Do you have the data stored in named volumes or hostpath volumes? If so you should be fine, otherwise you can copy any data that you need out of the containers with

docker cp container:/path/to/files /target/folder/on/host

https://docs.docker.com/engine/reference/commandline/cp/

if you use an orchestrator you could e.g. drain the node, which terminates all containers on the host and after successful draining add the node back to the cluster. The concrete command would depend on the orchestrator of your choice.


Update

Question: I don't understand how the data volumes can be related to the log configuration. If I had data stored in named volumes or host path volumes I would be fine, but I didn't see the relation to my question.

Answer: Correct, functionality-wise, the info regarding volumes is just added for you such that you do not lose data unknowingly / unrecoverably.

like image 101
ckaserer Avatar answered Sep 22 '25 21:09

ckaserer