Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip reserved (com.docker. io.docker, org.dockerproject) labels on docker commit #42037

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Feb 17, 2021

Docker uses reserved label namespaces on containers to store runtime information.
For example, when creating a service (docker service create), deploying a stack
(docker stack deploy), or running a compose project (docker-compose up),
docker respectively adds com.docker.swarm, com.docker.stack, and
com.docker.compose labels to store metadata used at runtime.

These labels are not set by users, but when commiting such a container, they
currently end up in the image that was committed.

This patch updates CreateImageFromContainer to remove labels in the reserved
namespace.

Some remarks should be made to this change:

  • This patch only accounts for docker commit; docker build still allows
    committing labels in the reserved namespaces
  • Because of the above, committing a container that was started from an image
    that has labels in the reserved namespaces, will strip these labels, and
    thus remove the labels from the image that is created.
  • Other actions (docker run, docker create) still allow these labels to be
    set, and also inherit these labels if they're started from an image that
    has labels in the reserved namespaces.

- Description for the changelog

When committing a container to an image using `docker commit`, reserved labels
(`com.docker.*`. `io.docker.*`, `org.dockerproject.*`) are no longer preserved in
the image that is created. These labels are automatically set by docker to store
runtime metadata, and should not preserved when committing to an image.

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah
Copy link
Member Author

Tentatively adding a "cherry-pick" label, but we can discuss if this is too much of a behavior change to consider for a patch release

@thaJeztah thaJeztah force-pushed the strip_reserved_labels_on_commit branch from a71e7f3 to 667733e Compare February 18, 2021 09:49
Comment string
Config *container.Config
Changes []string
KeepReservedLabels bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Good one, hmmm.. I think I originally thought it may be needed if there's uses elsewhere that need the old behavior, but I didn't do that in the end; let me remove

Extract the prefix-check to a function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
…ocker commit

Docker uses reserved label namespaces on containers to store runtime information.
For example, when creating a service (`docker service create`), deploying a stack
(`docker stack deploy`), or running a compose project (`docker-compose up`),
docker respectively adds `com.docker.swarm`, `com.docker.stack`, and
`com.docker.compose` labels to store metadata used at runtime.

These labels are not set by users, but when commiting such a container, they
currently end up in the image that was committed.

This patch updates `CreateImageFromContainer` to remove labels in the reserved
namespace.

Some remarks should be made to this change:

- This patch only accounts for `docker commit`; `docker build` still allows
  committing labels in the reserved namespaces
- Because of the above, committing a container that was started from an image
  that has labels in the reserved namespaces, will strip these labels, and
  thus remove the labels from the image that is created.
- Other actions (`docker run`, `docker create`) still allow these labels to be
  set, and also inherit these labels if they're started from an image that
  has labels in the reserved namespaces.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the strip_reserved_labels_on_commit branch from 667733e to 13edc7f Compare February 18, 2021 18:47
@thaJeztah
Copy link
Member Author

Discussing in the maintainers meeting, and we can exclude all labels on commit. The classic builder probably doesn't not need it - we need to double check this (LABEL foo=bar does not use a container that it commits), and for manual docker commit, there's the option to explicitly set a label through docker commit -c "LABEL foo=bar".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker commit commits compose labels
3 participants