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

Introspection of external port #1270

Closed
terinjokes opened this issue Jul 23, 2013 · 15 comments
Closed

Introspection of external port #1270

terinjokes opened this issue Jul 23, 2013 · 15 comments
Labels
area/networking kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny

Comments

@terinjokes
Copy link

For some services, it would be nice to be able to introspect the external port associated with an internal port.

@crosbymichael
Copy link
Contributor

@terinjokes docker ps displays both internal and external port information. Does that work for you?

@terinjokes
Copy link
Author

@crosbymichael: No, though the initial bug report isn't helpful.

To clarify, it would be helpful if inside the docker instance, there was an official means to query about itself, including the external port being mapped to a local port.

@shykes
Copy link
Contributor

shykes commented Aug 24, 2013

I agree this is needed.

In 0.7 I would like to find a solution to a bunch of networking problems and requests. This is one of them.

@terinjokes
Copy link
Author

@shykes Do you have an idea of how this might work from the perspective of a image maintainer? I'm starting to work on improvements to the Dockerfile this affects, and would be open to providing feedback.

@terinjokes
Copy link
Author

Looks like part of this came in 0.6.5's links feature, I'm looking into that now.

@GaretJax
Copy link
Contributor

GaretJax commented Nov 7, 2013

As far as I can tell, the links feature does not solve this exact problem, but it could be solved in a similar way by just adding an environment variable to the container. Something along the lines of SELF_xxx_TCP_PORT=yyy (or_UDP_).

@mbrevoort
Copy link

+1 for exporting host mapped ports via environment variables like the links feature. It should also export the host IP as well. In other words, the container should be able to introspect how it is externally reachable.

@terinjokes
Copy link
Author

+1 to @mbrevoort for explaining what I'm wanting in a much more straightforward fashion.

@crosbymichael
Copy link
Contributor

@mbrevoort What do we do when the container is not publishing a port to the docker host or publishes to localhost of the docker host machine?

@mbrevoort
Copy link

@crosbymichael I think the container should only be presented with the environment variables when the -p option is specified for port(s) that the containers EXPOSE.

The ip seems like a sticky area.

One option would be to populate an environment variable with the ip if it was specified with the -p option as well (e.g. ip::containerPort as in 10.10.10.2::8080) so you might get something like this:

SELF_8080_TCP_PORT=49153
SELF_8080_IP=10.10.10.2

However, if you use 0.0.0.0 that isn't helpful (e.g. 0.0.0.0:8080:8080).

Maybe the host isn't included in this; maybe the host would have to be passed in with -e as you would today. The port would still be super helpful though in cases where you are relying on Docker to bind to a random free port.

@danbeaulieu
Copy link

+1. In our situation we have a lot of containers coming and going and rely on dynamic port allocation. The applications inside the containers need to know how to tell the outside world how to route to themselves, knowing the host ip and external port are required.

@crosbymichael crosbymichael removed their assignment May 1, 2014
@crosbymichael crosbymichael removed this from the 0.7.1 milestone May 1, 2014
@jhliptak
Copy link

+1 Adding the ability to link to yourself would allow me to not run privileged containers (to use the API socket).

@erikh erikh added the ICC label Jul 16, 2014
@matleh
Copy link

matleh commented Aug 5, 2014

+1 that feature would allow a container to announce itself for service discovery (using etcd for example). Currently that has to happen outside of the container (with a "sidekick" in CoreOS).

@tamsky
Copy link
Contributor

tamsky commented Oct 14, 2015

It certainly would be nice if docker -d was a responsible member of society... and on every container create event, it would also place the output from docker inspect into the new container's root at some well known location, perhaps: /docker-metadata.

A simple but inefficient substitute for the above fits in a tweet or the more verbose:

# Requires docker v.1.8.0 or later
while true ; do
    for container in $(docker ps -q) ; do
        docker inspect ${container} 2>&1 >/tmp/${container}.meta &&
        docker cp /tmp/${container}.meta ${container}:/docker-metadata &&
        rm /tmp/${container}.meta
        sleep 5
    done
done

The above shell snippet probably constitutes a working fix for: #3778 #8427 #1270.

@thaJeztah
Copy link
Member

Looks like this is a duplicate of #1270, which is opened after this issue, but has more activity, so for housekeeping I'll close this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/networking kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny
Projects
None yet
Development

Successfully merging a pull request may close this issue.