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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With