Skip to content

Commit 37522d4

Browse files
authored
Update command to connect to PG database in README (#240)
* Update command to connect to PG database in README Use `docker exec` on the running container rather than booting up another postgres container to connect to the database * Provide different options for connecting to the database
1 parent a0353f4 commit 37522d4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@ In order to run a basic container capable of serving a PostGIS-enabled database,
2121

2222
For more detailed instructions about how to start and control your Postgres container, see the documentation for the `postgres` image [here](https://registry.hub.docker.com/_/postgres/).
2323

24-
Once you have started a database container, you can then connect to the database as follows:
25-
26-
docker run -it --link some-postgis:postgres --rm postgres \
27-
sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'
24+
Once you have started a database container, you can then connect to the database either directly on the running container:
25+
26+
docker exec -ti some-postgis psql -U postgres
27+
28+
... or starting a new container to run as a client. In this case you can use a user-defined network to link both containers:
29+
30+
docker network create some-network
31+
32+
# Server container
33+
docker run --name some-postgis --network some-network -e POSTGRES_PASSWORD=mysecretpassword -d postgis/postgis
34+
35+
# Client container
36+
docker run -it --rm --network some-network postgis/postgis psql -h some-postgis -U postgres
37+
38+
Check the documentation on the [`postgres` image](https://registry.hub.docker.com/_/postgres/) and [Docker networking](https://docs.docker.com/network/) for more details and alternatives on connecting different containers.
2839

2940
See [the PostGIS documentation](http://postgis.net/docs/postgis_installation.html#create_new_db_extensions) for more details on your options for creating and using a spatially-enabled database.
3041

0 commit comments

Comments
 (0)