Where does $ POSTGRES_PORT_5432_TCP_ADDR and $ POSTGRES_PORT_5432_TCP_PORT come from?

I am trying to postgres dockers by following the official postgres post at https://registry.hub.docker.com/_/postgres/ .

The following commands are launched in the document and activated:

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 does $ POSTGRES_PORT_5432_TCP_PORT and $ POSTGRES_PORT_5432_TCP_ADDR come from?

+5
source share
1 answer

They become available for the second container that you launch through the Docker binding mechanisms.

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

When the two containers are connected, Docker will set some environment variables in the target container to provide software detection of information related to the source container.

...

The following template:
...

  • PORT__ADDR will only contain the IP address from the URL (for example, WEBDB_PORT_8080_TCP_ADDR = 172.17.0.82).
  • PORT__PORT will only contain the port number from the URL (for example, WEBDB_PORT_8080_TCP_PORT = 8080).
+7
source

Source: https://habr.com/ru/post/1209949/


All Articles