[GIS] Geoserver to PostGres database using a hostname

geoserverpostgresql

I am trying to connect GeoServer to a PostGres Database with PostGIS extensions installed, but I need to use the host name becauuse the IP address may change. I am running geoserver and postgis in linked docker containers (see https://docs.docker.com/userguide/dockerlinks/), and restarting a container may result in a change of IP address. However, I have full control over the hostname. My /etc/hosts contains the entry:

172.17.0.244    postgis

If I configure GeoServer to use host 172.17.0.244 it connects fine, but if I specify postgis if doesn't connect. Is this just not possible with GeoServer, or am I doing something wrong?

Best Answer

By default, Postgres allows access from only local users on the same server, since you can connect via an Ip Address, you must have configured some security already, so to allow the hostname, you should only need to do the following ..

Edit your pg_hba.conf file for your PostGres installation add the following entry

# Allow any user from hosts in the example.com domain to connect to
# any database if the user's password is correctly supplied.
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             postgis                 md5

You can refer Postgres documentation Here! for detailed security options.

Related Question