8

Can I update labels on a container using docker-compose without restarting the container?

Ideal scenario: - change labels in docker-compose.yml - save docker-compose.yml - run a command to update the labels without restarting the container

uberrebu
  • 3,597
  • 9
  • 38
  • 73
adamsfamily
  • 1,746
  • 19
  • 37

1 Answers1

6

As a general rule, changing the settings or code running inside a container involves deleting and restarting the container. This is totally normal, and docker-compose up will do it for you when necessary. (Remember to make sure any data you care about is stored outside the container.)

At a Docker API level, there are only a limited set of things that can be changed in the Update a container call, and labels aren’t one of those. That means anything that manages a container, whether direct docker commands or Docker Compose, must always delete and recreate a container to change its labels.

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • 1
    Got it! I wasn't aware of it. I found the following links confirming this: https://github.com/moby/moby/issues/15496 and https://github.com/moby/moby/pull/18958. I wish it would be possible to tweak minor changes in traefik-labels without bringing down a container but it's apparently not possible. – adamsfamily Sep 24 '19 at 20:01
  • Not a solution to your problem, but you can work around it by using the [File provider](https://doc.traefik.io/traefik/providers/file/) as a way to tweak configuration without restarting your services. – Krasimir Jul 24 '22 at 14:18