From e853f8a4e925f67db034036b74f0780a4031f55b Mon Sep 17 00:00:00 2001 From: doublebyte1 Date: Mon, 11 Dec 2017 16:16:39 +0100 Subject: [PATCH 1/4] - Updated example of how-to connect to a postgres database: - explain how-to connect to a postgres db, by IP/DNS or container name, using the POSTGRES_DB_HOST environment variable. - remove reference to legacy docker --link --- geonetwork/variant-postgres.md | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/geonetwork/variant-postgres.md b/geonetwork/variant-postgres.md index af892d8a0..e84e36820 100644 --- a/geonetwork/variant-postgres.md +++ b/geonetwork/variant-postgres.md @@ -8,28 +8,30 @@ In order to setup the connection from geonetwork, you **must** inject the follow If your postgres instance is listening on a non-standard port, you must also set that variable: - `POSTGRES_DB_PORT`: postgres port on your database server (defaults to `5432`) -### Linking to a postgres container +### Connecting to a postgres database -Linking to a postgres container, is pretty straightforward: - `--link :postgres` - -For instance, if you want to run the official image for postgres, you could launch it like this: - -```console -$ docker run --name some-postgres -p 5432:5432 -d postgres -``` - -And then you could launch geonetwork, linking to this container, and setting the required environment variables: - -```console -$ docker run --name geonetwork -d -p 8080:8080 --link some-postgres:postgres -e POSTGRES_DB_USERNAME=postgres -e POSTGRES_DB_PASSWORD=mysecretpassword geonetwork:postgres -``` - -### Connecting to a postgres instance - -If you want to connect to a postgres server running somewhere, you need to pass an extra environment variable, containing the IP address for this server (which could be localhost, if you are running it locally). - `POSTGRES_DB_HOST`: IP address of your database server +If you want to connect to a postgres server, you need to pass an extra environment variable, containing the IP address for this server (which could be localhost, if you are running it locally). - `POSTGRES_DB_HOST`: IP address of your database server For instance, if the server is running on `192.168.1.10`, on port `5434`, the username is `postgres` and the password is `mysecretpassword`: ```console $ docker run --name geonetwork -d -p 8080:8080 -e POSTGRES_DB_HOST=192.168.1.10 -e POSTGRES_DB_PORT=5434 -e POSTGRES_DB_USERNAME=postgres -e POSTGRES_DB_PASSWORD=mysecretpassword geonetwork:postgres ``` + +If you want to use the container name as `POSTGRES_DB_HOST`, just make sure that containers can discover each other, by **running them in the same user-defined network**. For instance, you can create a bridge network: + +```console +$ docker network create --driver bridge mynet +``` + +Then if you want to run the official image of postgres, using `$POSTGRES_DB_HOST` as container name, you could launch it like this: + +```console +$ docker run --name $POSTGRES_DB_HOST --network=mynet -d postgres +``` + +And then you could launch geonetwork, making sure you join the same network, and setting the required environment variables, including the `POSTGRES_DB_HOST`: + +```console +$ docker run --name geonetwork -d -p 8080:8080 --network=mynet -e POSTGRES_DB_HOST=$POSTGRES_DB_HOST -e POSTGRES_DB_PORT=5432 -e POSTGRES_DB_USERNAME=postgres -e POSTGRES_DB_PASSWORD=mysecretpassword geonetwork:postgres +``` From 8e9fed3c072b58a580c8a070fe975203e44f3a93 Mon Sep 17 00:00:00 2001 From: doublebyte1 Date: Tue, 12 Dec 2017 13:01:47 +0100 Subject: [PATCH 2/4] - Updated documentation about how-to connect geonetwork to a postgres database, avoiding references to localhost. Only two use cases are presented: - connecting to an existing external database instance (using dns) - connecting to a postgres container by name (full reproducible example is presented) --- geonetwork/variant-postgres.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/geonetwork/variant-postgres.md b/geonetwork/variant-postgres.md index e84e36820..5b0f5b683 100644 --- a/geonetwork/variant-postgres.md +++ b/geonetwork/variant-postgres.md @@ -10,15 +10,16 @@ If your postgres instance is listening on a non-standard port, you must also set ### Connecting to a postgres database -If you want to connect to a postgres server, you need to pass an extra environment variable, containing the IP address for this server (which could be localhost, if you are running it locally). - `POSTGRES_DB_HOST`: IP address of your database server +If you want to connect to a postgres server, you need to pass an extra environment variable, `POSTGRES_DB_HOST`, +containing the address of this server. -For instance, if the server is running on `192.168.1.10`, on port `5434`, the username is `postgres` and the password is `mysecretpassword`: +If you want to connect to an **external database server**, you can use either the IP address or the DNS as `POSTGRES_DB_HOST`. For instance, if the server is running on `mydns.net`, on port `5434`, the username is `postgres` and the password is `mysecretpassword`: ```console -$ docker run --name geonetwork -d -p 8080:8080 -e POSTGRES_DB_HOST=192.168.1.10 -e POSTGRES_DB_PORT=5434 -e POSTGRES_DB_USERNAME=postgres -e POSTGRES_DB_PASSWORD=mysecretpassword geonetwork:postgres +$ docker run --name geonetwork -d -p 8080:8080 -e POSTGRES_DB_HOST=mydns.net -e POSTGRES_DB_PORT=5434 -e POSTGRES_DB_USERNAME=postgres -e POSTGRES_DB_PASSWORD=mysecretpassword geonetwork:postgres ``` -If you want to use the container name as `POSTGRES_DB_HOST`, just make sure that containers can discover each other, by **running them in the same user-defined network**. For instance, you can create a bridge network: +If are want to **run postgres on a container**, you can use the container name as `POSTGRES_DB_HOST`: just make sure that containers can discover each other, by **running them in the same user-defined network**. For instance, you can create a bridge network: ```console $ docker network create --driver bridge mynet From 618bbf942e420fc399bf871a7d7681c8416811c3 Mon Sep 17 00:00:00 2001 From: doublebyte1 Date: Tue, 12 Dec 2017 13:15:06 +0100 Subject: [PATCH 3/4] - replaced environmental variable $POSTGRES_DB_HOST, by an actual name - 'some-postgres', so that users can copy-paste the example. --- geonetwork/variant-postgres.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/geonetwork/variant-postgres.md b/geonetwork/variant-postgres.md index 5b0f5b683..3a5148b8a 100644 --- a/geonetwork/variant-postgres.md +++ b/geonetwork/variant-postgres.md @@ -25,14 +25,14 @@ If are want to **run postgres on a container**, you can use the container name a $ docker network create --driver bridge mynet ``` -Then if you want to run the official image of postgres, using `$POSTGRES_DB_HOST` as container name, you could launch it like this: +Then if you want to run the official image of postgres, using `some-postgres` as container name, you could launch it like this: ```console -$ docker run --name $POSTGRES_DB_HOST --network=mynet -d postgres +$ docker run --name some-postgres --network=mynet -d postgres ``` And then you could launch geonetwork, making sure you join the same network, and setting the required environment variables, including the `POSTGRES_DB_HOST`: ```console -$ docker run --name geonetwork -d -p 8080:8080 --network=mynet -e POSTGRES_DB_HOST=$POSTGRES_DB_HOST -e POSTGRES_DB_PORT=5432 -e POSTGRES_DB_USERNAME=postgres -e POSTGRES_DB_PASSWORD=mysecretpassword geonetwork:postgres +$ docker run --name geonetwork -d -p 8080:8080 --network=mynet -e POSTGRES_DB_HOST=some-postgres -e POSTGRES_DB_PORT=5432 -e POSTGRES_DB_USERNAME=postgres -e POSTGRES_DB_PASSWORD=mysecretpassword geonetwork:postgres ``` From 9013c0dddc6ba169c47b1da1104f644abe15e7f1 Mon Sep 17 00:00:00 2001 From: doublebyte1 Date: Wed, 13 Dec 2017 09:26:50 +0100 Subject: [PATCH 4/4] - fixed multi-line statement. --- geonetwork/variant-postgres.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/geonetwork/variant-postgres.md b/geonetwork/variant-postgres.md index 3a5148b8a..50f7a6033 100644 --- a/geonetwork/variant-postgres.md +++ b/geonetwork/variant-postgres.md @@ -10,8 +10,7 @@ If your postgres instance is listening on a non-standard port, you must also set ### Connecting to a postgres database -If you want to connect to a postgres server, you need to pass an extra environment variable, `POSTGRES_DB_HOST`, -containing the address of this server. +If you want to connect to a postgres server, you need to pass an extra environment variable, `POSTGRES_DB_HOST`, containing the address of this server. If you want to connect to an **external database server**, you can use either the IP address or the DNS as `POSTGRES_DB_HOST`. For instance, if the server is running on `mydns.net`, on port `5434`, the username is `postgres` and the password is `mysecretpassword`: