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

  • Running docker-compose with mysql and own docker container
  • Unable to access my web2py app login page by running docker container using gae
  • Docker : Install Maven dependencies during build stage only?
  • Host Global Python Object in Docker Container
  • Docker-Compose - Server exposes several ports but only one of the ports is not accessible in the client
  • Multiple docker images run from docker file
  • 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.

  • Using Nginx as micro service API gateway
  • Not able to connect to wurstmeister/kafka
  • RabbitMQ on Docker: Permission denied when chown-ing erlang cookie
  • APK is not installing in docker emulator
  • Docker Compose v3 Ports issue
  • How to connect to MongoDB running in Docker container?
  • 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.