Skip to content

Set container_uuid environment#7685

Closed
rhatdan wants to merge 4 commits intomoby:masterfrom
rhatdan:machine-id
Closed

Set container_uuid environment#7685
rhatdan wants to merge 4 commits intomoby:masterfrom
rhatdan:machine-id

Conversation

@rhatdan
Copy link
Contributor

@rhatdan rhatdan commented Aug 22, 2014

If you are running with systemd as init 1 and specify the container_uuid environment
variable, systemd will create /etc/machine-id with the correct data.

Then on the host you can setup journald to watch the container.

systemd only allows 32 chars in the UUID stored in /etc/machine-id

Then we can later apply a different patch to setup journald to watch
containers from the host and log all syslog/stdout/stderr data together
int the hosts journal.

The following link explains what systemd expects to be setup.

http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/

This should replace

#3506

Docker-DCO-1.1-Signed-off-by: Dan Walsh [email protected] (github: rhatdan)

@LK4D4
Copy link
Contributor

LK4D4 commented Aug 22, 2014

@rhatdan Could you provide image and run command with which I can test this?

@crosbymichael
Copy link
Contributor

nice, I like this approach

@LK4D4
Copy link
Contributor

LK4D4 commented Aug 22, 2014

@rhatdan You should write integration-cli test.
And I didn't get expected ID from /etc/machine-id with codekoala/arch:latest and fedora/systemd-systemd:latest. I think it is some hardcoded /etc/machine-id in these images.

@rhatdan
Copy link
Contributor Author

rhatdan commented Aug 22, 2014

It will not override an existing /etc/machine-id. So I guess you need to make sure there is no /etc/machine-id in the image, before running. I have not tested this with a systemd container yet. I am just following the example given on the document page. I will look into testing or having someone test this next week to make sure it works properly. (I am on Vacation next week).

@SvenDowideit
Copy link
Contributor

is this really so insignificant to not need documentation?

@rhatdan
Copy link
Contributor Author

rhatdan commented Aug 25, 2014

I added some mention of container_uuid to the examples and a line to docker run man page. Do you want this mentioned elsewhere. Not sure we document any other environment variables being set.

@crosbymichael
Copy link
Contributor

ping @shykes

What do you think about this proposed change? Are we ready to support letting containers know the ID?

@rhatdan rhatdan force-pushed the machine-id branch 2 times, most recently from 4d700e2 to 5a533b4 Compare September 2, 2014 19:21
@rhatdan
Copy link
Contributor Author

rhatdan commented Sep 2, 2014

Back from Vacation, updating Pull Requests and seeing if there is anything I can do to move these along.

@SvenDowideit
Copy link
Contributor

Docs LGTM - @jamtur01 @fredlf @ostezer

Copy link

Choose a reason for hiding this comment

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

I think "Container ID" here should be "container ID".

@fredlf
Copy link
Contributor

fredlf commented Sep 4, 2014

LGTM. Ping @jamtur01

@vbatts
Copy link
Contributor

vbatts commented Sep 5, 2014

@crosbymichael @shykes this would also close #6481

@jamtur01
Copy link
Contributor

Docs LGTM

@gdm85
Copy link
Contributor

gdm85 commented Sep 21, 2014

Will there be a way to disable this? I can perfectly imagine that I wouldn't like my processes to know they're running within Docker by checking for the existance of this environment variable; sorry for the pedant minimalism, but I would also not clutter (further) the environment variables with this feature.
I understand systemd expects this environment variable and it would be nice if it were already set, but on the other hand not everybody is running systemd in containers...

@rhatdan
Copy link
Contributor Author

rhatdan commented Sep 21, 2014

Well you could unset container_uuid within the containers init. I think adding an option to stop this would be a waste.

@LK4D4
Copy link
Contributor

LK4D4 commented Sep 21, 2014

At first, there is still no tests. And I still want to see how this works.

@rhatdan
Copy link
Contributor Author

rhatdan commented Sep 22, 2014

@LK4D4 Added integration test.

@rhatdan
Copy link
Contributor Author

rhatdan commented Sep 22, 2014

What is the magic command to allow me to test only my test? Not the entire test suite?

@vbatts
Copy link
Contributor

vbatts commented Sep 22, 2014

TESTFLAGS='-run TestCLIImageTagRemove' make test-integration-cli

@rhatdan
Copy link
Contributor Author

rhatdan commented Nov 13, 2014

hostname makes sense to override, Env container_uuid not so much.

@rhatdan rhatdan force-pushed the machine-id branch 2 times, most recently from ab8686a to 519f7d0 Compare December 2, 2014 17:35
@rhatdan rhatdan force-pushed the machine-id branch 3 times, most recently from 6b308ac to ecab633 Compare December 13, 2014 12:16
@LK4D4
Copy link
Contributor

LK4D4 commented Dec 16, 2014

@rhatdan Hello, I just realized that we talking about inside container env, so will not this be the same like:

docker run -it --rm -e container_uuid=$(uuidgen) busybox printenv container_uuid

@tiborvass
Copy link
Contributor

How about we just set the Docker container ID in a CID envvar ?

@jessfraz
Copy link
Contributor

I would be okay with adding container_uuid if we also add container_id or something like that so systemd and users can benefit :) but this is just my opinion
maybe an okay compromise?

@shykes
Copy link
Contributor

shykes commented Dec 16, 2014

I'm fine with making the container's ID available to the application in a well-know and well-supported env variable. It would be strictly better than applications trying to infer it from something that is not fully supported, like the hostname.

I think we should avoid the term "uuid" since, technically, the current ID is not a uuid, and even if it were, we reserve the right to change the allocation method later. For example with the new trust primitives, it is likely that each container will have its own encryption keypair, and we could use the public key as an identifier. As far as the application is concerned, all that matters is that there is a single, globally unique string which identifies the container in which it is running.

So, I suggest we store the container ID in $cid, document that fact in the specification so that applications can rely on it, and move on.

@shykes
Copy link
Contributor

shykes commented Dec 16, 2014

I realize that systemd expects the precise variable name $container_uuid. I don't think that's an issue, in this context systemd is the application, and if you're packaging an image running systemd, there are various ways to "translate" $cid to whatever the application expects. It doesn't seem viable for us to try to honor natively all the requirements of all the applications we might call. What if a systemd competitor expects another env variable, or if a future version of systemd changes the variable name? Will we be expected to change?

Hopefully this makes sense to everyone. It seems like a no-brainer to me.

@vbatts
Copy link
Contributor

vbatts commented Dec 16, 2014

@shykes true, but what if there were an abstraction that would allow manipulation for a $container_id. So if a UUID env is expected, then that could be accomplished?
Something like the container create/start/stop hooks we talked about?

@rhatdan
Copy link
Contributor Author

rhatdan commented Dec 16, 2014

Turns out there is more to getting systemd wired up correctly then just passing in the container_uuid. I have extended this patch to handle setting up journalling to allow journal inside the container to write messages that the journal outside of the container can see. I have to work on one more patch to setup the machine-ctl to recognise that a there is a container running. docker needs to send the UUID to docker via dbus to make this happen. Once it is fully instrumented then there would be more container information available in the HOST OS, including using machinectl, ps -o machine, journal -M machine etc.

@rhatdan rhatdan force-pushed the machine-id branch 4 times, most recently from 29931c7 to 2a9dd30 Compare December 19, 2014 20:27
If you are running with systemd as init 1 and specify the container_uuid environment
variable, systemd will create /etc/machine-id with the correct data.

Then on the host you can setup journald to watch the container.

systemd only allows 32 chars in the UUID stored in /etc/machine-id

Then we can later apply a different patch to setup journald to watch
containers from the host and log all syslog/stdout/stderr data together
int the hosts journal.

The following link explains what systemd expects to be setup.

http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/

This should replace

moby#3506

Docker-DCO-1.1-Signed-off-by: Dan Walsh <[email protected]> (github: rhatdan)
…content in container

Docker-DCO-1.1-Signed-off-by: Dan Walsh <[email protected]> (github: rhatdan)
Docker-DCO-1.1-Signed-off-by: Dan Walsh <[email protected]> (github: rhatdan)
Docker-DCO-1.1-Signed-off-by: Dan Walsh <[email protected]> (github: rhatdan)
@icecrime
Copy link
Contributor

icecrime commented Jan 6, 2015

Review session with @tiborvass @unclejack @crosbymichael

Although the PR initially started about "exposing" container ID, the requirements have changed along the way to supporting the systemd journal. We believe with this new information we should take a step back and think about the requirements to support the systemd journal with Docker containers.

We're closing the PR as it won't be merged as it is, but discussions can continue here.

@icecrime icecrime closed this Jan 6, 2015
@rhatdan
Copy link
Contributor Author

rhatdan commented Jan 6, 2015

This is not unexpected, since if I could not convince you to support setting an Environment Variable within an image, I doubt you would consider mounting /var/lib/journal. Sadly it leaves those of us looking to run systemd correctly within a container little options.

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

Successfully merging this pull request may close these issues.