Link between two docker containers in a network

I have a docker network between geoserver and postgres. When I do docker inspect container name I can see the two are linked. When I exec into the geoserver container I can ping the postgres container but when I try to connect to a postgres db from within the geoserver container I get an error

psql: could not translate host name postgres to address: Name or service not known

  • DOCKER - LAMP Stack issues - Premade Image
  • Duplicate mappings when building docker package using sbt-native-packager
  • Shortcut command for docker-compose build + down + up
  • dockerized cassandra: java.lang.OutOfMemoryError: Java heap space
  • Why use docker? Aren't java files like WAR files already running on JVM?
  • CI: Should I run tests directly or through Docker container?
  • Here is an example of my docker-compose:

    version: '2'
      image: kartoza/postgis:9.5-2.2
      image: geonode/geoserver
      hostname: geonode-geoserver
        - postgres:postgres
        - "8181:8080"

    I know with docker networks the /etc/hosts file is not populated. How can I enable accessing the database from geoserver container.

  • docker mysql start failed, unable to create temporary file, permission denied
  • All job data lost when running Jenkins in Docker and when Jenkins container is stopped
  • Nginx behind Traefik Docker Swarm mode real ip
  • Clone server to docker image
  • How to make my docker run on a specified linux kernel version?
  • What is the docker command to run jenkins container in windows
  • 3 Solutions collect form web for “Link between two docker containers in a network”

    The geoserver service is probably starting before the postgres service is available.


    You should use a defined network for resolve names without links and use depends_on for postgres start before geoserver.

    in the geoserver service definition change:

    • postgres:postgres


    • postgres:kartoza/postgis:9.5-2.2

    You need to match the service name to the image name

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.