Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Proposal: One Meta Data to Rule Them All => Labels #9882
Conversation
ibuildthecloud
referenced this pull request
Jan 3, 2015
Closed
API: Allow for container IDs to be forced through the remote API. #9854
|
Thanks, Darren!
Fully agree on this one. Docker should offer the means to store, search and retrieve the data, but have no opinion on what they are used for, or what (naming)conventions are used. If Docker itself is using meta-data for something, that is just an implementation, just like any other system using the meta-data. The data stored in a label is just free-form text as well; if an implementation decides to use it for storing JSON, that's fine, but Docker doesn't offer special treatment for those values; no parsing, validation or nested search for JSON properties. Indexing / performanceTo be useful (for example, fetch a container via a "custom" id), querying meta-data should be fast. Useful indexes should probably be present, including "partial" matches or wild-card support, both on "keys" and "values". For example, getting all containers that have a labels with namespace/prefix starting with Scope / VisibilityWe should probably ask if meta data is only accessible from "outside" containers (in case of meta-data on containers), or also from within a container; I can see use-cases where meta-data can be useful inside a container. How to control access is something to be discussed (also wrt read/read-write) InheritanceIn case of Image and Container meta-data; should images share the same meta-data as containers running from it? Will they be inherited, but kept separate? Or are they "merged" when creating a container instance? |
|
I also agree that docker should not dictate how the data gets used or formatted. I personally think docker tries to dictate things a bit too often. We should recommend a best practice, but if someone wants to ignore best practice, they might have a good reason for it. However I don't like the term 'label'. Most systems I've ever dealt with have treated a label as value-only data, not key/value (one example being github labels). Just to clarify what I mean, a label would be something like |
This was referenced Jan 4, 2015
|
I like this FWIW |
|
Paging @vieux and @aluzzardi, as this may be very relevant to their interests. I also think it's a really good idea. Chef search is very similar and one of its best features. |
|
I want to make it clear that my intention is to quickly move this forward. I want to find what we can implement now that will give the minimally viable value but also put us on clear path to adding more functionality. @thaJeztah - Comments below Indexing/PerformanceI completely agree that fast lookup is required. That is one of the fundamental differences between environment variables and labels. For containers I think this can be easily achieved by just keeping the labels in memory in the current data structures. Searching for a label will just be iterating over the list of containers in memory. This means at it’s worse searching for a label will be as slow as Images become more difficult as you have more images than containers, typically. For images a real index should be built. The problem though is that docker networks are coming soon and volumes will probably not be too far. It seems we should find one consistent approach for labels that works for all object types. As such, I would like to defer on search for images by tag. I’ve currently seen a higher demand for fast lookup of containers, but not the same for images. I’m not saying the use cases don’t exist, just that containers are a higher priority. The way in which one can search is largely based on the underly index. So supporting wildcard, regexp, etc. has real technical implications. I think we need a good query syntax, but for the first pass I think it is safe to support “give me all containers that have label foo” and “give me all containers that have label foo equal to bar”. The syntax would be Scope/VisibilityFirst off, scope visibility doesn’t really matter until we have an introspection service. So this is obviously a discussion that will happen elsewhere, but regardless I’ll say what I think it should be. Labels should follow the existing pattern of ports. That being that they are private by default and must be explicitly published. Defining a label is the same as InheritanceI hope you notice a trend in my comments in that we should just follow existing patterns. For inheritance I would expect labels follow the same approach as environment variables. I honestly haven’t given a huge amount of thought to this, but I think the ENV approach should be sufficient. @phemmer I completely agree that label is a bad term. Unfortunately the precedence has already been set with host labels and Kubernetes labels. I have a strong opinion that it's better to be consistently wrong then inconsistently right. I think we should just stick with the ill named “label.” ImplementationI have every intention of pushing this through as fast as possible. I’m going to code the implementation of this hopefully today based off of @rhatdan’s existing work in docker#8955. I'm optimistic the community can come to a consensus. |
ibuildthecloud
referenced this pull request
Jan 5, 2015
Closed
Proposal: Allow specification of LABEL Name/Value pairs in image json content #8955
|
Labels would be awesome for fig/docker compose. Tracking images with tags would allow users to use any name for their images and containers, and would address some of the performance issues with the current version.
It seems to me like inheritance could be entirely client-side. A client which is creating a container from an image should be able to decide which labels to copy over to the container. |
jamtur01
added
the
/project/doc
label
Jan 6, 2015
SvenDowideit
commented on an outdated diff
Jan 6, 2015
SvenDowideit
commented on the diff
Jan 6, 2015
| @@ -11,7 +11,7 @@ let b:current_syntax = "dockerfile" | ||
| syntax case ignore | ||
| -syntax match dockerfileKeyword /\v^\s*(ONBUILD\s+)?(ADD|CMD|ENTRYPOINT|ENV|EXPOSE|FROM|MAINTAINER|RUN|USER|VOLUME|WORKDIR|COPY)\s/ | ||
| +syntax match dockerfileKeyword /\v^\s*(ONBUILD\s+)?(ADD|CMD|ENTRYPOINT|ENV|EXPOSE|FROM|MAINTAINER|RUN|USER|LABEL|VOLUME|WORKDIR|COPY)\s/ |
SvenDowideit
Contributor
|
SvenDowideit
and 1 other
commented on an outdated diff
Jan 6, 2015
| @@ -322,6 +322,17 @@ default specified in `CMD`. | ||
| > the result; `CMD` does not execute anything at build time, but specifies | ||
| > the intended command for the image. | ||
| +## LABEL | ||
| + LABEL <key>=<value> <key>=<value> <key>=<value> ... | ||
| + | ||
| + --The `LABEL` instruction allows you to describe the image your `Dockerfile` | ||
| +is building. `LABEL` is specified as name value pairs. This data can | ||
| +be retrieved using the `docker inspect` command | ||
| + | ||
| + | ||
| + LABEL Description="This image is used to start the foobar executable" Vendor="ACME Products" | ||
| + LABEL Version="1.0" | ||
| + |
SvenDowideit
Contributor
|
phemmer
and 1 other
commented on an outdated diff
Jan 6, 2015
| @@ -1326,6 +1327,11 @@ Create a new image from a container's changes | ||
| "Cmd":[ | ||
| "date" | ||
| ], | ||
| + "Labels": [ | ||
| + "Vendor=Acme", | ||
| + "License=GPL", | ||
| + "Version=1.0" | ||
| + ], |
phemmer
Contributor
|
|
Do we ever anticipate labels being added/removed on an already existing container? If so, storing them in the config data precludes this possibility. |
|
I agree with pretty much everything in this proposal - it's basically the one I would've written. As @dnephin says, Compose will be a primary consumer of this feature. |
bfirsh
added
the
UX
label
Jan 6, 2015
|
I can go along with this, just as long as something finally gets merged to allow us to add Meta Data. Even if we can just settle on a name Meta->UserData->Label... |
bfirsh
and 3 others
commented on an outdated diff
Jan 7, 2015
| @@ -124,6 +124,11 @@ Create a container | ||
| "OpenStdin":false, | ||
| "StdinOnce":false, | ||
| "Env":null, | ||
| + "Labels": [ | ||
| + "Vendor=Acme", | ||
| + "License=GPL", | ||
| + "Version=1.0" | ||
| + ], |
bfirsh
Contributor
|
bfirsh
commented on an outdated diff
Jan 7, 2015
| @@ -1501,6 +1504,7 @@ removed before the image is removed. | ||
| --ipc="" Default is to create a private IPC namespace (POSIX SysV IPC) for the container | ||
| 'container:<name|id>': reuses another container shared memory, semaphores and message queues | ||
| 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure. | ||
| + -l, --label=[] Set labels |
bfirsh
Contributor
|
jessfraz
added
the
Proposal
label
Jan 7, 2015
Current approachAs it's implemented right now, it is the following Dockerfile
Docker run Querying
StatusI've written the code, tests, and some documentation. I feel the approach is pretty solid but there are two remaining issues I see.
The nameLabels is consistent with host labels and Kubernetes. It has already been pointed out that because these labels allow multiple keys with the same name they are already different from Kubernetes. Labels is not the obvious term I believe because most people don't think of key/value pairs. Meta data seems like the more accepted term. Meta data would be inconsistent with host labels, but we could standardize on that name going forward as we apply this same approach to networks and volumes in the future. Data StructureThe current code is using @vieux @aluzzardi @crosbymichael Opinions? |
|
Sorry to pile on the design questions, but I'm concerned about multiple labels with the same key. My gut reaction is to not allow it, because then it's impossible to override a label - if an image specifies |
|
I'm guessing this is an artifact of how the ENV parser works? -Erik On Wed, 2015-01-07 at 08:41 -0800, Aanand Prasad wrote:
|
|
@aanand I agree, I also don't like multiple labels with different names. My assumption is that there was already a long discussion about this for host labels, as host labels were implemented this way. Maybe @vieux can chime in. Rancher.io will be a consumer of this API and I would personally prefer to not allow multiple keys as it complicates interactions. Additionally, even though we say you can have multiple keys with the same name it is not possible to do that from a Dockerfile. The Dockerfile is always assuming that you are overriding the value. Come to think of it the way the |
|
I also don't want multiple labels with the same key. |
|
@ibuildthecloud are we labelling images or containers here ? the |
|
@vieux Both images and containers. The label from the Dockerfile goes in Config.Labels and ContainerConfig.Labels of the image and then gets merged into the container in Config.Labels |
|
@shykes Can you make the oh so critical decision of whether the format should be |
|
I presume the container won't have access to this info? Also, will we be able to add labels from the build cli? ie |
|
@SvenDowideit the container does not have access to this info. You currently can't add labels from the build cli, the label has to be in the Dockerfile. What would be the need to assign labels from the CLI and not from the Dockerfile? |
dreamcat4
commented
Jan 9, 2015
|
Hello. I'm still quite new to docker. So my opinion might be a bit naive on un-informed. Personally I would be in favour of calling it Metadata instead of Labels, and have the option to be allowing arbitrary json structures under it there. It may sound like an overkill, but I am guessing if you implemented the feature that way, then it would be truly flexible and future-proof forever (and still should not require docker to be dictating or managing anything more either). Being able to store arbitrary metadata would be more inter-operable with external tools (that can then store their own formatted metadata structures without any restriction). So it would simplify those scenarios a lot. And then such future intro/intra-spection feature could be more powerful too. And I guess in fig.yml (docker compose), you would finally be able to specify arbitrary yml structures in there: e.g.
Where most people would be using the metadata key like simple labels (as you guys have already honed in on). But then some fewer more complex cases, when someone knows what they are doing and really needs it, can specify arbitrary json structure, or have 3rd party management tools populate them automatically (for the cluster and distributed management, etc). So I guess what I am really saying is: if we can just call them Sorry to come in with different ideas so late to the discussion. |
|
@dreamcat4 The problem with supporting nested JSON structures, is that will also require a lot of extra handling in Docker. While you prefer to use JSON, other people may want to store plain-text. The next step would become that people want to modify parts of that JSON structure, or search for a deeply nested property (and want Docker to be optimized for that). The current look at things is to make as little assumptions as possible. The value you're storing is a simple string. What you want to put in that string is up to you, or the package using it. However, this doesn't prevent you to store JSON, it just has to be encoded as a string; {
"Labels": {
"myFancyLabel": [
"{\"Vendor\":[\"Acme\"],\"License\":[\"GPL\"],\"Version\":[\"1.0\"],\"foo\":[\"bar\",\"baz\",\"bam\"]}"
]
}
}To use the JSON, the software that uses it, has to decode it before using. |
dreamcat4
commented
Jan 9, 2015
|
@thaJeztah ah, i now see your original comment near the top where you first mention encoding json into a string value. Sorry I missed that the first time around. Don't doubt your assessment about the implementation being harder. I don't think the current proposed version of it needs to be any much different. I am not arguing for that. Just that the name of the feature as I do agree that complex search expressions do irk a lot of people. Because they already IRK me too when using complex go templates in What if we could eventually turn the problem on it's head? And instead simply converted any non-string objects to their json string representations, before passing them to those newly exposed string matching and search functions? To cache those json blobs representations would improve the speed of successive searching. Then they still get handled and output to sstdout as the sort of embedded json strings that you showed me here in your recent example. But critically that their underlying native representation need not be forced to be a string (not right now, but eventually, when the feature is improved upon). For arbitrary structured metadata. The same proposed text search interface(s) would then continue to work externally exactly the same as before. For in the case of complex data the output would be just json blobs for those complex data instead. Sorry. I feel I am repeating myself here. In fig.yml, I need to express arbitrary metadata that is nested. For intro-intra-spection. In docker compose if I follow your solution to my problem then that would mean constructing a pretty horrendous encoded json blob (as per the example given above) and inserting that into a string keys under a |
Not necessarily; that will completely depend on the software using the docker API. If Fig (or Docker Compose, or Crane, or ...) decides to support structured labels, they could allow the user to enter it as YAML or JSON. It's the responsibility of that software to convert it to a string before sending the label to the Docker API. So (to stick with Fig/Compose as an example), you could write the {
"Labels": {
"fig.project" : ["my-project.example.com"],
"fig.service" : ["service"],
"fig.metadata" : ["[\"label1=value1\",\"label2=value2\",{\"feature1\":{\"sub_structure1_1\":[\"arbitrary json \/ yaml here\"]}},{\"feature2\":[\"metadata for a different unrelated feature \/ etc.\"]}]"]
}
}Where The same would apply to (nested) searching in that "JSON", only in reverse; Docker itself doesn't support that, so Fig would have to fetch the labels from Docker and convert them back to JSON when searching. Perhaps, in the future, it would be possible to extend this via "plugins", e.g. being able to plug-in a custom "label" storage and/or search engine. But, for now, that's out of scope for this Proposal. |
jainvipin
commented
Jan 9, 2015
|
+1 like the proposal (and others that are referenced in this proposal) @ibuildthecloud wrote:
It probably is worth stating what else includes in etc.for example network/network-endpoints as defined in docker#9983. Probably not for endpoints, and may be for network, but the scope of which objects can be associated with labels should be specified. Can I also assume that docker state/libpack will distribute the labels (as it becomes available). |
This was referenced Jan 10, 2015
dreamcat4
commented
Jan 11, 2015
|
@thaJeztah OK then. I guess I would be happy with that. |
|
I would say I don't care much about labels for the images. Why not make 2 PRs ? one for containers and one for images ? Containers should be quite small. Otherwise I think we should add a new column to |
|
I like this a lot. Let's make it happen. My one concern: I think labels should have single values. Several reasons:
|
dreamcat4
commented
Jan 14, 2015
|
I agree with @bfirsh. Single values. |
This was referenced Jan 14, 2015
|
I have changed my pull request to use labels instead of UserData. This seems to follow the standard set in docker -d. We believe labels should be single value. We really need this for labeled images. We are looking at putting data into the image to instruct the commands for install, config, run. We want to make the container image contain all information to define how an application will run even if the application consists of multiple containers. |
|
One thing worth noting is that if we have single-value labels here, daemon labels should also be consistent. @vieux – is this feasible, do you think? |
That's not what the title of this PR suggests! But in any case I agree, searchable labels have a different purpose to annotations. Using structured data is not the only difference, however. #9013 was motivated by a design for docker plugins (extensions, proxies, whatever). Crucial to the design is that the annotations can be changed while the container is running, and interested parties (e.g., plugins) are told that this has happened. I don't see that addressed here. For the record, I don't think the solution is to try and make this proposal encompass even more features. If anything it ought to be drastically simple -- so not only no structured values, but nothing that would make you want to use it with encoded structured values, or to rely on the values as anything other than opaque tokens. |
|
Yes lets keep this simple and get it merged. We could extend this proposal later or add alternatives in the future. For now, we just want to allow image developers to add opaque data to the image. |
rade
commented
Jan 14, 2015
|
A crucial, motivating feature for #9013, and a key distinction from env vars, is the ability to add/update/delete metadata for stopped or running containers. This proposal does not appear to address that. |
|
Thanks Darren for taking the initiative on this! A few notes: 1) On overall designI'm a big +1 on the need for arbitrary user data as you know. 2) On the word "label"I'm not a huge fan of the term "label", but I don't think it contradicts another well-established term, I don't have a strong opinion and we already use it for "host labels" (see daemon flags). Consistency matters, so I would say let's use that unless someone has a very strong opinion backed by strong evidence. NOTE: I saw consistency with Kubernetes mentioned as an argument: that is utterly unimportant. Consistency within the project is important. Consistency with well-established standard practices is also important. Consistency with young and immature is not. If we start using consistency with projects like that as an argument, we're opening a pandora box: there will always be at least 1 bleeding edge project, somewhere, which is consistent with our pet terminology. Nobody cares. Consistency within the same project is essential, but consistency with other projects is nice-to-have, at best, unless they're massively adopted. Kubernetes is even more immature than Docker which is saying a lot, so it really doesn't matter if we stay consistent with them. Hopefully this is not a controversial statement. We use the term "label" already at the host level (see daemon flags), so that's a more compelling argument for consistency. 3) On format of valuesI agree that single string values are better, because:
4) On namespacingI understand your point @ibuildthecloud but I think we should still enforce at least a convention. It's important to do this now, because in practice it's the only opportunity we'll get. Once real-world users and tools start taking over the entire namespace, it will be extremely hard to add new restrictions later without breaking reverse compatibility (which would go against our core principles). So I suggest the following simple convention:
|
|
I think the word "label" has wide understanding as the meaning we are giving it. "Tags" is a close second. The fact we also use the term "label" for daemons is also a plus. I have no strong feelings about namespacing. @aanand – got any thoughts on this? |
|
I don't feel particularly strongly about namespacing, but I would like to make one point: @shykes observes correctly that it's almost always better to make a decision you can reverse later, rather than one that locks you in. In the case of namespaced keys, though, both options actually involve lock-in, just for different sets of tools:
So either way it's a risk. To me, it feels like the breakage in (1) is going to be a much more common case, which is an argument for enforcing namespacing from the start. |
|
I agree with @aanand. Insisting on namespaced keys is better than removing namespaces afterwards. Some notes / questions;
|
|
I'm glad to see this PR is moving along. Let me summarize the points so far. It seems we are very close to decisions on most of these points.
Based on my summary I will be updating the code and documentation as follows
|
|
@thaJeztah I don't see much harm in just enforcing what I just posted. This is a very light restriction. By enforcing the regexp now we can reserve space for internal keys by having keys that don't have a period, or maybe have a "_" or "/" in them. |
moxiegirl
commented on an outdated diff
Mar 16, 2015
| @@ -59,6 +59,7 @@ pages: | ||
| - ['userguide/dockerimages.md', 'User Guide', 'Working with Docker Images' ] | ||
| - ['userguide/dockerlinks.md', 'User Guide', 'Linking containers together' ] | ||
| - ['userguide/dockervolumes.md', 'User Guide', 'Managing data in containers' ] | ||
| +- ['userguide/labels-custom-metadata.md', 'User Guide', 'Labels - custom meta-data in Docker' ] |
|
|
moxiegirl
commented on an outdated diff
Mar 16, 2015
| @@ -71,15 +71,33 @@ This endpoint now returns `SystemTime`, `HttpProxy`,`HttpsProxy` and `NoProxy`. | ||
| ### What's new | ||
| +**New!** |
moxiegirl
Contributor
|
moxiegirl
commented on the diff
Mar 16, 2015
| `POST /containers/(id)/attach` and `POST /exec/(id)/start` | ||
| **New!** | ||
| Docker client now hints potential proxies about connection hijacking using HTTP Upgrade headers. | ||
| +`POST /containers/create` | ||
| + | ||
| +**New!** | ||
| +You can set labels on container create describing the container. |
moxiegirl
Contributor
|
moxiegirl
and 1 other
commented on an outdated diff
Mar 16, 2015
| `POST /containers/(id)/attach` and `POST /exec/(id)/start` | ||
| **New!** | ||
| Docker client now hints potential proxies about connection hijacking using HTTP Upgrade headers. | ||
| +`POST /containers/create` | ||
| + | ||
| +**New!** | ||
| +You can set labels on container create describing the container. | ||
| + | ||
| +`GET /containers/json` | ||
| + | ||
| +**New!** | ||
| +This endpoint now returns the labels associated with each container (`Labels`). |
moxiegirl
Contributor
|
moxiegirl
commented on an outdated diff
Mar 16, 2015
| @@ -190,6 +195,8 @@ Json Parameters: | ||
| - **OpenStdin** - Boolean value, opens stdin, | ||
| - **StdinOnce** - Boolean value, close stdin after the 1 attached client disconnects. | ||
| - **Env** - A list of environment variables in the form of `VAR=value` | ||
| +- **Labels** - A map of labels and their values that will be added to the |
moxiegirl
Contributor
|
|
GLOBAL: In the docs and the syntax pick key/value or name/value and use whichever you use consistently. I tried to standardize on key/value in my comments. |
moxiegirl
commented on the diff
Mar 16, 2015
| @@ -328,6 +328,27 @@ default specified in `CMD`. | ||
| > the result; `CMD` does not execute anything at build time, but specifies | ||
| > the intended command for the image. | ||
| +## LABEL |
moxiegirl
Contributor
|
moxiegirl
commented on an outdated diff
Mar 16, 2015
| @@ -791,6 +791,8 @@ Creates a new container. | ||
| -h, --hostname="" Container host name | ||
| -i, --interactive=false Keep STDIN open even if not attached | ||
| --ipc="" IPC namespace to use | ||
| + -l, --label=[] Set meta data on the container (e.g., --label=com.example.key=value) |
|
|
moxiegirl
commented on an outdated diff
Mar 16, 2015
moxiegirl
commented on an outdated diff
Mar 16, 2015
| @@ -1662,6 +1665,8 @@ removed before the image is removed. | ||
| --link=[] Add link to another container | ||
| --lxc-conf=[] Add custom lxc options | ||
| -m, --memory="" Memory limit | ||
| + -l, --label=[] Set meta data on the container (e.g., --label=com.example.key=value) | ||
| + --label-file=[] Read in a line delimited file of labels |
|
|
moxiegirl
commented on an outdated diff
Mar 16, 2015
| @@ -1835,6 +1840,36 @@ An example of a file passed with `--env-file` | ||
| This will create and run a new container with the container name being | ||
| `console`. | ||
| + $ sudo docker run -l my-label --label com.example.foo=bar ubuntu bash |
moxiegirl
Contributor
|
moxiegirl
commented on an outdated diff
Mar 16, 2015
moxiegirl
commented on an outdated diff
Mar 16, 2015
| @@ -0,0 +1,194 @@ | ||
| +page_title: Labels - custom meta-data in Docker | ||
| +page_description: Learn how to work with custom meta-data in Docker, using labels. | ||
| +page_keywords: Usage, user guide, labels, meta-data, docker, documentation, examples, annotating | ||
| + | ||
| +## Labels - custom meta-data in Docker |
moxiegirl
Contributor
|
|
When I got to your final and new page on labels, I see that labels can apply to images or containers. So, in my edits just apply the proper noun for the context. |
|
@ibuildthecloud Hey if you can't see the MD in my comments let me know, I stored that last file offline just in case. |
|
@moxiegirl I can't see the MD source. For most of the comments I just made the appropriate changes but if you could stick docs/sources/userguide/labels-custom-metadata.md in a gist or something that would be great. |
|
@moxiegirl Please take another look! :-) |
|
@moxiegirl I believe all comments have been address and I copied in your version of docs/sources/userguide/labels-custom-metadata.md |
|
LGTM |
icecrime
added
status/3-docs-review
and removed
status/2-code-review
labels
Mar 17, 2015
SvenDowideit
commented on the diff
Mar 17, 2015
| @@ -143,6 +143,21 @@ A Dockerfile is similar to a Makefile. | ||
| **CMD** executes nothing at build time, but specifies the intended command for | ||
| the image. | ||
| +**LABEL** | ||
| + -- `LABEL <key>[=<value>] [<key>[=<value>] ...]` | ||
| + The **LABEL** instruction adds metadata to an image. A **LABEL** is a | ||
| + key-value pair. To include spaces within a **LABEL** value, use quotes and | ||
| + blackslashes as you would in command-line parsing. | ||
| + | ||
| + ``` | ||
| + LABEL "com.example.vendor"="ACME Incorporated" | ||
| + ``` | ||
| + | ||
| + An image can have more than one label. To specify multiple labels, separate each | ||
| + key-value pair by a space. |
SvenDowideit
Contributor
|
SvenDowideit
commented on the diff
Mar 17, 2015
| @@ -102,6 +104,12 @@ IMAGE [COMMAND] [ARG...] | ||
| 'container:<name|id>': reuses another container shared memory, semaphores and message queues | ||
| 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure. | ||
| +**-l**, **--label**=[] | ||
| + Set metadata on the container (e.g., --label=com.example.key=value) |
ibuildthecloud
Contributor
|
SvenDowideit
commented on the diff
Mar 17, 2015
| @@ -102,6 +104,12 @@ IMAGE [COMMAND] [ARG...] | ||
| 'container:<name|id>': reuses another container shared memory, semaphores and message queues | ||
| 'host': use the host shared memory,semaphores and message queues inside the container. Note: the host mode gives the container full access to local shared memory and is therefore considered insecure. | ||
| +**-l**, **--label**=[] | ||
| + Set metadata on the container (e.g., --label=com.example.key=value) | ||
| + | ||
| +**--label-file**=[] | ||
| + Read in a file of labels (EOL delimited) |
|
|
SvenDowideit
commented on the diff
Mar 17, 2015
| @@ -328,6 +328,27 @@ default specified in `CMD`. | ||
| > the result; `CMD` does not execute anything at build time, but specifies | ||
| > the intended command for the image. | ||
| +## LABEL | ||
| + | ||
| + LABEL <key>=<value> <key>=<value> <key>=<value> ... | ||
| + | ||
| +The `LABEL` instruction adds metadata to an image. A `LABEL` is a | ||
| +key-value pair. To include spaces within a `LABEL` value, use quotes and | ||
| +blackslashes as you would in command-line parsing. |
|
|
SvenDowideit
commented on the diff
Mar 17, 2015
| @@ -328,6 +328,27 @@ default specified in `CMD`. | ||
| > the result; `CMD` does not execute anything at build time, but specifies | ||
| > the intended command for the image. | ||
| +## LABEL | ||
| + | ||
| + LABEL <key>=<value> <key>=<value> <key>=<value> ... | ||
| + | ||
| +The `LABEL` instruction adds metadata to an image. A `LABEL` is a | ||
| +key-value pair. To include spaces within a `LABEL` value, use quotes and | ||
| +blackslashes as you would in command-line parsing. | ||
| + | ||
| + LABEL "com.example.vendor"="ACME Incorporated" | ||
| + | ||
| +An image can have more than one label. To specify multiple labels, separate each | ||
| +key-value pair by an EOL. |
|
|
SvenDowideit
commented on the diff
Mar 17, 2015
| @@ -1832,8 +1837,39 @@ An example of a file passed with `--env-file` | ||
| $ sudo docker run --name console -t -i ubuntu bash | ||
| -This will create and run a new container with the container name being | ||
| -`console`. | ||
| +A label is a a `key=value` pair that applies metadata to a container. To label a container with two labels: | ||
| + | ||
| + $ sudo docker run -l my-label --label com.example.foo=bar ubuntu bash | ||
| + | ||
| +The `my-label` key doesn't specify so the label defaults to an empty |
|
|
SvenDowideit
commented on the diff
Mar 17, 2015
| @@ -1832,8 +1837,39 @@ An example of a file passed with `--env-file` | ||
| $ sudo docker run --name console -t -i ubuntu bash | ||
| -This will create and run a new container with the container name being | ||
| -`console`. | ||
| +A label is a a `key=value` pair that applies metadata to a container. To label a container with two labels: | ||
| + | ||
| + $ sudo docker run -l my-label --label com.example.foo=bar ubuntu bash | ||
| + | ||
| +The `my-label` key doesn't specify so the label defaults to an empty | ||
| +string(`""`). To add multiple labels, repeat the label flag (`-l` or | ||
| +`--label`). | ||
| + | ||
| +The `key=value` must be unique. If you specify the same key multiple times |
SvenDowideit
Contributor
|
SvenDowideit
commented on the diff
Mar 17, 2015
| -`console`. | ||
| +A label is a a `key=value` pair that applies metadata to a container. To label a container with two labels: | ||
| + | ||
| + $ sudo docker run -l my-label --label com.example.foo=bar ubuntu bash | ||
| + | ||
| +The `my-label` key doesn't specify so the label defaults to an empty | ||
| +string(`""`). To add multiple labels, repeat the label flag (`-l` or | ||
| +`--label`). | ||
| + | ||
| +The `key=value` must be unique. If you specify the same key multiple times | ||
| +with different values, each subsequent value overwrites the previous. Docker | ||
| +applies the last `key=value` you supply. | ||
| + | ||
| +Use the `--label-file` flag to load multiple labels from a file. Delimit each | ||
| +label in the file with an EOL mark. The example below loads labels from a | ||
| +labels file in the current directory; |
SvenDowideit
Contributor
|
SvenDowideit
commented on the diff
Mar 17, 2015
| +The `my-label` key doesn't specify so the label defaults to an empty | ||
| +string(`""`). To add multiple labels, repeat the label flag (`-l` or | ||
| +`--label`). | ||
| + | ||
| +The `key=value` must be unique. If you specify the same key multiple times | ||
| +with different values, each subsequent value overwrites the previous. Docker | ||
| +applies the last `key=value` you supply. | ||
| + | ||
| +Use the `--label-file` flag to load multiple labels from a file. Delimit each | ||
| +label in the file with an EOL mark. The example below loads labels from a | ||
| +labels file in the current directory; | ||
| + | ||
| + $ sudo docker run --label-file ./labels ubuntu bash | ||
| + | ||
| +The label-file format is similar to the format for loading environment variables | ||
| +(see `--env-file` above). The following example illustrates a label-file format; |
|
|
SvenDowideit
commented on the diff
Mar 17, 2015
| @@ -0,0 +1,194 @@ | ||
| +page_title: Labels - custom metadata in Docker | ||
| +page_description: Learn how to work with custom metadata in Docker, using labels. | ||
| +page_keywords: Usage, user guide, labels, metadata, docker, documentation, examples, annotating | ||
| + | ||
| +## Labels - custom metadata in Docker | ||
| + | ||
| +You can add metadata to your images, containers, and daemons via | ||
| +labels. Metadata can serve a wide range of uses. Use them to add notes or | ||
| +licensing information to an image or to identify a host. | ||
| + | ||
| +A label is a `<key>` / `<value>` pair. Docker stores the values as *strings*. | ||
| +You can specify multiple labels but each `<key>` / `<value>` must be unique. If | ||
| +you specify the same `key` multiple times with different values, each subsequent | ||
| +value overwrites the previous. Docker applies the last `key=value` you supply. |
SvenDowideit
Contributor
|
SvenDowideit
commented on the diff
Mar 17, 2015
| + | ||
| +- Keys should only consist of lower-cased alphanumeric characters, | ||
| + dots and dashes (for example, `[a-z0-9-.]`) | ||
| + | ||
| +- Keys should start *and* end with an alpha numeric character | ||
| + | ||
| +- Keys may not contain consecutive dots or dashes. | ||
| + | ||
| +- Keys *without* namespace (dots) are reserved for CLI use. This allows end- | ||
| + users to add metadata to their containers and images, without having to type | ||
| + cumbersome namespaces on the command-line. | ||
| + | ||
| + | ||
| +These are guidelines and are not enforced. Docker does not *enforce* them. | ||
| +Failing following these guidelines can result in conflicting labels. If you're | ||
| +building a tool that uses labels, you *should* use namespaces for your label keys. |
SvenDowideit
Contributor
|
SvenDowideit
commented on the diff
Mar 17, 2015
| + LABEL <key>=<value> <key>=<value> <key>=<value> ... | ||
| + | ||
| +The `LABEL` instruction adds metadata to an image. A `LABEL` is a | ||
| +key-value pair. To include spaces within a `LABEL` value, use quotes and | ||
| +blackslashes as you would in command-line parsing. | ||
| + | ||
| + LABEL "com.example.vendor"="ACME Incorporated" | ||
| + | ||
| +An image can have more than one label. To specify multiple labels, separate each | ||
| +key-value pair by an EOL. | ||
| + | ||
| + LABEL com.example.label-without-value | ||
| + LABEL com.example.label-with-value="foo" | ||
| + LABEL version="1.0" | ||
| + LABEL description="This text illustrates \ | ||
| + that label-values can span multiple lines." |
SvenDowideit
Contributor
|
SvenDowideit
commented on the diff
Mar 17, 2015
| +string. For example, consider this JSON: | ||
| + | ||
| + | ||
| + { | ||
| + "Description": "A containerized foobar", | ||
| + "Usage": "docker run --rm example/foobar [args]", | ||
| + "License": "GPL", | ||
| + "Version": "0.0.1-beta", | ||
| + "aBoolean": true, | ||
| + "aNumber" : 0.01234, | ||
| + "aNestedArray": ["a", "b", "c"] | ||
| + } | ||
| + | ||
| +You can store this struct in a label by serializing it to a string first: | ||
| + | ||
| + LABEL com.example.image-specs="{\"Description\":\"A containerized foobar\",\"Usage\":\"docker run --rm example\\/foobar [args]\",\"License\":\"GPL\",\"Version\":\"0.0.1-beta\",\"aBoolean\":true,\"aNumber\":0.01234,\"aNestedArray\":[\"a\",\"b\",\"c\"]}" |
SvenDowideit
Contributor
|
|
yup, minor nits - basically, most of my questions are answered elsewhere, but the reader won't know that at the time. LGTM - though if you address the nits, it'll Look even better :) |
|
Thanks all, and thanks Darren for your patience! @moxiegirl will take care of the final adjustments in a separate PR. |
icecrime
pushed a commit
that referenced
this pull request
Mar 17, 2015
icecrime
merged commit b6ac111
into
moby:master
Mar 17, 2015
vieux
removed
the
status/3-docs-review
label
Mar 17, 2015
|
@icecrime Thank you so much for helping move this along. |
|
Wow! Happy to see this merged. Thanks @ibuildthecloud for finally making this happen! |
wyaeld
commented
Mar 17, 2015
|
huge thank-you to all the people who worked on this and the various discussions that led to it, such a useful building block One question (not to try and increase scope here though). Do people think it makes sense for the distribution components ( |
TomasTomecek
commented on the diff
Mar 17, 2015
| @@ -143,6 +143,21 @@ A Dockerfile is similar to a Makefile. | ||
| **CMD** executes nothing at build time, but specifies the intended command for | ||
| the image. | ||
| +**LABEL** | ||
| + -- `LABEL <key>[=<value>] [<key>[=<value>] ...]` | ||
| + The **LABEL** instruction adds metadata to an image. A **LABEL** is a | ||
| + key-value pair. To include spaces within a **LABEL** value, use quotes and | ||
| + blackslashes as you would in command-line parsing. |
thaJeztah
Member
|
dreamcat4
referenced this pull request
in michaelsauter/crane
Mar 17, 2015
Closed
Support new Docker 1.6.0 features - Labels #160
|
This is huge. Only been waiting on this one for about a year.... |
|
Yaaaay. What an excellent birthday present. Thanks all for your help. We're going to try and get Compose support in for this in the next release: docker/compose#1066 |
dreamcat4
commented
Mar 17, 2015
|
@bfirsh Well if you implement Compose support, please consider @thaJeztah's idea earlier on in this thread ^^. So compose can be auto-converting nested data structured into |
This was referenced Mar 19, 2015
nicornk
commented
Aug 3, 2015
|
Hi Guys, |
|
@nicornk Not possible. |
ibuildthecloud commentedJan 3, 2015
This is yet another meta data PR in an attempt to pull together multiple PRs hopefully into something we can get into Docker 1.5 (seriously, let's move fast).
Background
Some background... (from what I can gather). There is currently docker#8955 for adding UserData to a Dockerfile. Basically it adds the
USERDATA key=value key="long value"syntax to the Docker. Then there is docker#9013 which looks to add structured JSON data to a Dockerfile and a container in much the same fashion as Kubernete's annotations. Finally there is docker#9854 which discusses the need for meta data on container to help with Swarm and similar clustering systems. There are probably another 10 threads that @thaJeztah can find that also talk about the need to add meta data to containers.We need this...
We need meta data, it's clear user want it.
Labels
We already have labels on Hosts (Docker daemon) today. It seems that going forward we should be able to add labels to everything: Hosts, containers, volumes, images, etc. Let's just continue with that approach. Labels are simple key/value pairs in the style of
map[string]string. There have been comments to standarize the format of the keys such that we have namespaces or other means to prevent conflicts. Honestly I don't think that is all that necesary at the Docker level to dictate this. It's just good practice to namespace things. Whether you do "foo_bar" or "foo/bar" or "com.foo/bar", who really cares. If your going to use "id=3", well that's a bad name and somebody may clobber your value. I'm assuming some will disagree with me on this one. That's fine, I'll agree to a namespace standard just as long as it doesn't take three weeks and 132 comments to decide that DNS format is far superior to arbitrary strings split by "/".Labels are not structured data, and as such this PR is different from docker#9013, so that discussion can happen differently. Honestly, I'm not in favor of adding structured data to objects and having Docker maintain it. But if others disagree, so be it, we can have structured data as something else.
What about ENV vars
Yes, labels are very close to environment variables. You can add ENV to a Dockerfile and you can add them at container create. The basic difference here is that these key/values are not visible to the running processes in the container.
Lookup by Label
Another key attribute of labels is that you should be able to find an object based on it's label. This should initially be kept very simple. You can either say "give me all images/containers that have key foo." Or you can say "give me all images/containers that have foo=bar".
How should we go about doing this?
I think docker#8955 is the right start.
USERDATAshould be renamed toLABEL. Now that we haveLABELon images we need to add--label key=valuetodocker run/create. This is in the same fashion asENVand-etoday.Now the only thing left do to is to figure out how to query based on labels. We just need to add
--label fooor--label foo=bartodocker images/ps.It's just that simple folks
Okay, good? Alright, let's move forward...