Skip to content

Inside container access host + mapped ports #1424

@thijsterlouw

Description

@thijsterlouw

I would like to know, inside my container:

  1. host address of my container (docker0 link, eg 172.16.42.1). I know that I can pass this value at runtime of the container already, but the next value I cannot pass yet, thus I think it makes sense to have a uniform solution:
  2. the external value of the mapped port. Eg. I configured Docker to use port 8000 internally, but want to figure out which external port that is.
root@thijs:~# docker ps
ID                  IMAGE                         COMMAND             CREATED             STATUS              PORTS
1a4994c874f6        thijsterlouw/erlang3:latest   /usr/sbin/sshd -D   18 hours ago        Up 18 hours         49161->22, 49162->8000               
a63ec666e1e5        thijsterlouw/erlang2:latest   /usr/sbin/sshd -D   26 hours ago        Up 26 hours         49159->22, 49160->8000               
ab0a3e84fd1e        thijsterlouw/erlang2:latest   /usr/sbin/sshd -D   7 days ago          Up 27 hours         4369->4369, 49153->22, 49154->8000   

So Inside container ab0a3e84fd1e I want to be able to lookup value 49154 for port 8000.

Usecase for both of these values: Erlang distribution where the container should register with a port-mapper daemon the public (and not the private 8000) port.

This could be implemented nicely with a special environment variable. I think there is no harm in transparently making these values available, but I am also fine if it is possible to pass these values via the -e option of 'docker run'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions