-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Use labels instead of names to identify containers #1356
Conversation
return build_container_name(self.project, self.name, number, one_off) | ||
|
||
# TODO: this would benefit from github.com/docker/docker/pull/11943 | ||
# to remove the need to inspect every container |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very familiar with python, but does this currently require to inspect every container, or the containers after filtering by project (and service name)? Trying to determine how important moby/moby#11943 is for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the containers after filtering, so it's not so bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks, I was expecting that, but wasn't sure 😄
Fantastic stuff, thank you. Will merge once docker-py label support has landed. |
Will this be backwards-compatible with existing Compose projects? i.e. if I've got containers running that I started with the current stable version, then I upgrade and run |
Hm, perhaps interesting thought to add the version of compose that was used to create the containers as a label as well, in case there's some migration needed in future. |
Ah, good point. I think that might be a problem. I suspect it will look for containers using labels, find none, then attempt to create them, running into a 409 conflict error from docker. I think we'll need to do something to address that. We could release one version that falls back to trying to lookup by name, or Both of those run into the issue where it requires users to upgrade one version at a time though, skipping the intermediate version would still break things. Another option, which is usually my preference, is to provide a migration script, which would read a
@thaJeztah I think a compose version label would be a good idea |
Perhaps if def containers(self, *args, **kwargs):
containers = self._containers_using_labels(*args, **kwargs)
if not containers:
self._check_for_old_containers()
return containers
def _check_for_old_containers(self):
containers = self._containers_using_names()
if containers:
names = [c.name for c in containers]
raise UserError(
"""
Found containers that were created using an old version of Compose:
{}
You have two options:
- Migrate them with `docker-compose migrate-containers-1.3`
- Remove them with `docker rm -f {}`
""".format("\n".join(names), " ".join(names))
) |
This would mean checking for containers would still be potentially slow when there aren't any in the current project, but compared to how slow it is now we're only adding a single API call (doing a We can remove it in a later version once we're satisfied that most people have upgraded. |
@aanand I like that idea. If compose had a configuration file ( (Docker itself is working on some changes in the config files / structure) |
@dnephin liked the idea a lot. Does this PR remove service name entirely from the container name or still keep it around? I guess for readability of 'docker ps' output it might be nice to have them. How do the labels on the containers look like when containers are started from |
We keep container names, but they're now "write-only" - we don't look at them, except to figure out what the next numeric suffix should be. (I think eventually we should drop numeric suffixes in favour of something random, so that generating the next one doesn't involve an API call). Also, once this is merged, we'll be able to implement support for specifying custom container names. For that reason, it might make sense to revisit the output of
Something like this:
|
Or even a "Project" column; compose should now be able to get all containers that are managed by compose (filter by |
True - we can just look at the labels - but it's still an extra API call versus generating something random.
That might be cool: |
Yes! Thinking if we should keep track of the location of the yaml file where the project was started from (the project "home" directory) |
Actually, yes, that's a good idea and one I meant to suggest earlier:
|
Think that should be the location of the config (yaml), now that all paths are relative to that file (iirc), but yeah, something like that. On a side-note, there's a breaking change being worked on in Docker currently. I'm personally not really happy about that. Not sure if compose itself is affected directly, but compose users definitely, if they use bind-mounted volumes to mount their source code during development. See: |
1 similar comment
Think that should be the location of the config (yaml), now that all paths are relative to that file (iirc), but yeah, something like that. On a side-note, there's a breaking change being worked on in Docker currently. I'm personally not really happy about that. Not sure if compose itself is affected directly, but compose users definitely, if they use bind-mounted volumes to mount their source code during development. See: |
3926353
to
7b66f5e
Compare
I'm thinking |
fe07044
to
c5abf9e
Compare
We don't actually have access to the config path from I've added the compose version, that was easy enough. I'm going to focus on migration and backwards compatibility. |
👍 |
c5abf9e
to
50fdb00
Compare
Fully agree! one step at a time, no need to mingle multiple features into one. |
0335def
to
3c741c1
Compare
Alright, migration test added, and appears to be passing. There was actually a bug in the previous version, it would try to add labels to all projects, instead of just the current one. |
True, not a big issue I think, as long as the docs mention it's a temporary method. The migration is a nice extra and will only be used once for a project, so "shrugs" Changes look good to me (but again, I'm not a python coder, so just a general "feel" by glancing over it). I think what's remaining is;
Again, great work! |
Definitely not. |
👍 definitely worth a mention in the docs. People will try, which is fine, but it should be clear that they're on their own in that case. |
return int(self.name.split('_')[-1]) | ||
except ValueError: | ||
return None | ||
return int(self.labels.get(LABEL_CONTAINER_NUMBER) or 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ever expected/OK for a container not to have a number label? I feel like we should error out if we don't find one, unless I've missed a case. Same for the service label.
@moxiegirl @fredlf - your opinions on docs would be useful here. For context, we're making a change to Compose that means people will need to migrate their containers to a new format - but we're only going to keep it around for one version before dropping support for old containers. Compose will show a warning if it detects old-style containers, prompt you to run My question is: where should the document go? We don't plan to keep it around for a long time, so perhaps docs.docker.com isn't the right place and it should just go in a Markdown file on GitHub. |
@aanand My recommendations would be:
I would recommend the section in the release notes would only exist if we know there can be confusion. So, if no issues exist in the next release, the section goes away. For the Upgrade Compose section in the install --- that would remain a stable touchpoint even if it has a single line to rerun the Unfortunately, I have no cycles this release to add the section to install, if you agree and want to add it, I'll have time to review. |
@moxiegirl Thanks - I'll do that. I've opened an issue for it: #1425 |
Signed-off-by: Daniel Nephin <[email protected]>
Signed-off-by: Daniel Nephin <[email protected]>
3c741c1
to
6e98dec
Compare
Signed-off-by: Daniel Nephin <[email protected]>
6e98dec
to
62059d5
Compare
Rebased, and added an error to |
LGTM |
Use labels instead of names to identify containers
Great job guys! Thanks |
bravo! 👯 💃 👯 (only a matter of gusto atm, but shouldn't anything that is used package-wide like the constants in |
Resolves #1066
Should be compatible with #1269
Also includes:
create_container
andnext_container_number()
. I moved the logging intocreate_container()
instead of having it happen in all the callers, and changed it so thatfind_next_number()
only happens once.