-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Links and Container Naming #2162
Conversation
|
||
.. code-block:: bash | ||
|
||
docker run -d -e PASSWORD=docker crosbymichael/redis --requirepass=docker |
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.
It should be --requirepass docker
Love this idea! |
Reading the proposal, I do not fully understand this. Why are names and links related at all? Why can’t the host name, passed with I also do not understand, why the relationship has to be parent and child? Why the different levels? |
// Try to set the default name for a container if it exists prior to links | ||
// Ignore the error because if it already exists you will get an invalid constraint | ||
if _, err := runtime.containerGraph.Set(fmt.Sprintf("/%s", container.ID), container.ID); err != nil { | ||
utils.Debugf("Setting default id - %s", err) |
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.
do we really need to print it ? The debug looks scary now
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.
I guess not but if there was an error other than an invalid constraint it would be good to know. That was my only reason for outputting to debug.
The pseudo-docs here appear to be somewhat out of date. The first example mentions REDIS_PORT_6379_ADDR, but all I get is REDIS_PORT_6379_TCP (and REDIS_PORT and REDIS_NAME). Also, the later example has db_PORT_6379_ADDR, but the env vars are always all-uppercased, aren't they? I realize these are semi-unofficial, but official docs will probably at least be based in part on them, and us mere mortals are learning the links feature from them in the meantime. :) |
Oh, reading back up, I see you initially describe the correct vars, they're just not necessarily correct in the examples. 👍 |
This contains various operations that can replace the use of shelling out to "ip".
The sysinit code only uses /bin/ip to set a default gateway. This is pretty easy to do via netlink directly, so we can avoid the ip dependency.
We have our own netlink version of all the required calls now, so we can just skip the /sbin/ip dependency.
This just tries pinging first 127.0.0.1 and then 8.8.8.8. We can't ping via a dns name, because libresolv.so is missing from the test image, so dns resolving doesn't work.
This will be needed for later use in docker-init without a docker dependency
This allows docker-init to not import the main docker module, which means it won't e.g. pick up any sqlite dependencies.
Removed test cases that are no longer applicable with links and the port changes. Remove test case where a test was hitting an external ip.
This is as discussed with @shykes on IRC
Add close method to Runtime and Server to make sure that any underlying connections are cleaned up
This allows the user to toggle enabling and disabling intercontainer communication when they run the daemon.
Guys (@crosbymichael and @vieux) is this ready for review and merge? This branch is growing way too large, I'm seeing all sorts of things unrelated to links in there. |
Yes this is ready for a final review and merge. The only thing that is not releated to links in this branch is the static dockerinit changes, nothing else. |
Add name generator for container without -name
Remove docker link Do not add container id as default name Create an auto generated container name if not specified at runtime.
Add -name for docker run
Note: the spec in this issue is now out-of-date. But as long as the docs are not, it doesn't matter :) |
Links and Container Naming
NOTE @crosbymichael: I updated the text of the pull request to match the latest version :) |
Links - Spec
Links are a way of expressing a relationship between one container and another. When you link a container, you create a parent/child relationship between the two. As a side effect links also allow you to name containers and reference them by name. Containers can be references by more than one name.
Breaking changes
This the new link feature we will be disabling intercontainer communication by default. Containers will not be able to communicate with each other over the docker0 bridge without having a link to that container. Even with a link, a parent can only communicate to the ports exposed by the child and nothing more.
Initially links will be expressed by injecting the child's data into the parent's environment accessible via namespaced variables:
Examples
REDIS_ENV_{key}={value}
REDIS_PORT={value}
REDIS_PORT_6379_TCP={value}
.Create a named container
Link a container into another
Using the container named 'db1' from our previous example we will create a relationship between our webapp container and redis.
To create a link between two containers you add the
-link
flag to yourdocker run
command passing the name and alias of the container that you want to link as the child. The alias will be used as the namespace to set environment variables in the parent container. The format is-link <name>:<alias>
. The alias will be converted to ALL_CAPS when environment variables are created.Remove redis as a child of frontend
Introspecting the linked container's environment
Lets run another redis container with a password that the client must use to connect. We store the password in the environment of the container so we can use introspection to retreive the password by the parent.
Client Libs
With client libs you can simplify links more.
TLDR
Links are a way to express relationships between containers and allow introspection based on those relationships.