How do you register a Postgres container host on docker-compose up?

I have an app (Flask/Pony ORM) container that must register the host for a postgres db container on start up. How can I get the host’s (postgres container) location?

On my local set up I have “localhost” but this does not work in the app container.

  • docker: “build” requires 1 argument. See 'docker build --help'
  • anyway to setup npm credentials over `npm login` without reading input from STDIN?
  • Domain resolves on host machine but not inside docker container
  • ECONNREFUSED for Postgres on nodeJS with dockers
  • Is it possible to deploy a docker hub publicly hosted image to Kubernetes Container Engine without uploading it to Containers Registery?
  • Docker container blocking text/event-stream
  • I tried “172.17.0.2” which was what the pg containers IP when I was not using docker-compose.

    But both of these return an error.

    Is there a way to specify a host location for a particular container in the docker-compose file?

  • HAProxy over SSL with RabbitMQ SSL authentication + Kombu client - IOError('Socket Closed')
  • How can I make a HTTP request from one docker container to another linked container?
  • Cannot access a Kubernetes postgresql service from the outside
  • Hit a service running on localhost from inside a docker image
  • Does docker swarm mode (docker 1.13 & compose v3) really provides zero downtime rolling updates or deployments?
  • Docker bash prompt not display color
  • One Solution collect form web for “How do you register a Postgres container host on docker-compose up?”

    You must link your two container in your docker-compose file. Then you will be able to access to your database using the service name of the container.

    Example

    links:
      - postgres:postgres
    

    Link your docker-compose.yml if you need more help.

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