Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do $POSTGRES_PORT_5432_TCP_ADDR and $POSTGRES_PORT_5432_TCP_PORT come from?

Tags:

docker

I am trying docker postgres by following the official postgres image on https://registry.hub.docker.com/_/postgres/ .

In the document it run the following commands and get it to work:

docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
docker run -it --link some-postgres:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

So my question is where do $POSTGRES_PORT_5432_TCP_PORT and $POSTGRES_PORT_5432_TCP_ADDR come from?

like image 370
Ron Avatar asked Dec 27 '14 05:12

Ron


1 Answers

They are made available to the second container you start via the Docker linking mechanisms.

From https://docs.docker.com/userguide/dockerlinks/#environment-variables:

When two containers are linked, Docker will set some environment variables in the target container to enable programmatic discovery of information related to the source container.

...

The pattern followed is:
...

  • PORT__ADDR will contain just the IP address from the URL (e.g. WEBDB_PORT_8080_TCP_ADDR=172.17.0.82).
  • PORT__PORT will contain just the port number from the URL (e.g. WEBDB_PORT_8080_TCP_PORT=8080).
like image 72
dukebody Avatar answered Oct 19 '22 06:10

dukebody