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

Use labels instead of env variables #172

Closed
Nadrieril opened this issue May 31, 2015 · 24 comments
Closed

Use labels instead of env variables #172

Nadrieril opened this issue May 31, 2015 · 24 comments

Comments

@Nadrieril
Copy link

With the new labels addition to docker 1.6 (https://docs.docker.com/userguide/labels-custom-metadata), it would be cleaner to use labels instead of environment variables.

For example, we could set the label 'com.jwilder.nginx-proxy.virtual-host' to the host we want, and so on.

It need not be a breaking change, you can handle both behaviours at the same time

@thaJeztah
Copy link
Contributor

+1 thinking of this, I think I actually suggested this in #36 (comment)

Labels were already suggested in nginx-proxy/docker-gen#81 and implemented in nginx-proxy/docker-gen#82

So, it looks like this should be possible, with a modified template?

@md5
Copy link
Contributor

md5 commented May 31, 2015

@thaJeztah I think a new release of docker-gen still needs to be cut to include the latest changes.

@jwilder
Copy link
Collaborator

jwilder commented Jun 1, 2015

Yeah, env vars were initially used because labels didn't exist at the time. I'm in favor of supporting labels. though.

@jwilder
Copy link
Collaborator

jwilder commented Jun 2, 2015

docker-gen 0.4.0 has label support now.

@mathroc
Copy link

mathroc commented Jun 5, 2015

just a recommendation for when choosing the labels name "It's recommended that you use reverse-DNS notation to prevent your labels from conflicting with those used by other software." ( https://github.com/docker/compose/blob/master/docs/yml.md#labels )

also, it could replace #60 (labels might support "only" the new syntax host:xx and ENV vars are kept with the old behavior to avoid BC)

@thaJeztah
Copy link
Contributor

It's recommended that you use reverse-DNS notation

👍 I mentioned that in my original #36 (comment), but forgot to repeat it here. Thanks for the reminder!

@iBobik
Copy link

iBobik commented Jul 21, 2015

Sorry for dump question.

Does in mean that it will be possible to change e.g. host without restarting container?

@md5
Copy link
Contributor

md5 commented Jul 21, 2015

@iBobik Labels can only be set when a container is started (as far as I know), so supporting labels wouldn't help you change a hostname without restarting a container.

@Boran
Copy link

Boran commented Jul 30, 2015

@iBobik : I think labels can only be set when creating (not starting) a container, i.e. same limits as environment variables. It would be great if a container could be stopped, labels changed and restarted.

@ibnesayeed
Copy link

What is stopping this from happening?

@iBobik
Copy link

iBobik commented Jan 25, 2017 via email

@mathroc
Copy link

mathroc commented Jan 25, 2017

@iBobik, @jwilder already said he is in favor of supporting labels. maybe what's needed is a PR

ps: I guess the image should still support env vars too, labels should probably have higher priority than env var

@ibnesayeed
Copy link

@mathroc: guess the image should still support env vars too...

Absolutely! There is no reason to break the backward compatibility for such a popular image.

@ibnesayeed
Copy link

@Boran: @iBobik : I think labels can only be set when creating (not starting) a container, i.e. same limits as environment variables. It would be grate if a container could be stopped, labels changed and restarted.

This doesn't seem to be true now (maybe it was the case when you posted, but I doubt).

$ docker run --rm -it -e FOO=bar ubuntu
root@07ff6061fec7:/# echo $FOO
bar

Similarly,

$ docker run -d -l foo=bar --name=label-test ubuntu
$ docker inspect label-test | grep foo
                "foo": "bar"
$ docker rm label-test

The following is indeed present.

"Config": {
    "Labels": {
        "foo": "bar"
    }
}

@thaJeztah
Copy link
Contributor

@ibnesayeed what @Boran meant is that once a container is created, the labels cannot be updated, i.e. after docker create or docker run (which is docker create + docker start), you cannot update the labels without recreating the container.

t.b.h., I think that's ok, as container should be considered immutable, but there may be use cases that would like to do so without recreating the container.

@ibnesayeed
Copy link

@thaJeztah thanks for the clarification.

And yes, I too agree that containers are supposed to be immutable configuration wise and stateless when run so that other instances can be created from the corresponding image anytime and any number of times independently. This seems true for most of the practical cases where this image might be used. However, situations where keeping state is desired, how often those containers would switch domain names in their life time in any practical application? Having said that, if the env vars are there as a fallback then those niche cases can utilize that while rest of the community takes advantage of labels.

@ibnesayeed
Copy link

@mathroc: ... maybe what's needed is a PR

What is the scope of changes in order to support this? I guess the template is where all the magic will happen. Is there any other place where the changes needs to go?

@sudoforge
Copy link

If nobody has started working on this yet, I'd be happy to. I likely won't have time to complete it for another week or two, however.

@iBobik
Copy link

iBobik commented Sep 22, 2017 via email

Alexander-Krause-Glau pushed a commit to Alexander-Krause-Glau/rpi-docker-nginx-proxy that referenced this issue Mar 30, 2018
@Nadrieril
Copy link
Author

I have not used docker or this project in 5 years now, and this issue seems dead. I'll close this and someone else can open it again if they're interested.

@anLizard
Copy link

I'd be very interested in this feature, as label changes on containers do not require the container to be rebuilt.
Like mentioned before, support for both environment variables and labels seems like a good idea.

@sudoforge
Copy link

You might be interested in traefik for local use instead of this.

@anLizard
Copy link

You might be interested in traefik for local use instead of this.

I've actually used both Traefik and Caddy-Docker-Proxy before, which is how I know about labels in the first place.

Traefik ended up being too confusing and convoluted to set up, and Caddy-Docker-Proxy was lacking in features.

Nginx-proxy/dockergen with nginx is just the right level of versitility and simplicity, but that's the one feature I've been missing!

@buchdag
Copy link
Member

buchdag commented Feb 16, 2022

@anLizard does the Docker daemon emit an event when there is a label change on a container ?

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

No branches or pull requests