Issue linking containers in Docker using Docker-compose

I’m using Docker to get my micro services architecture ready.
I’m facing some problem trying to link one container with another using docker-compose.

Basically I have a container for a postgressql image, and the a java micro service developed with spring boot that should connect to the database container.

  • Docker TLS Error on Ubuntu
  • Connecting Docker container to corporate LDAP server through SSL
  • Spring Cloud Eureka Client
  • chmod not work with virtualbox share folder
  • GPU becomes unavailable when computer goes to sleep
  • Gitlab CI and Docker throws error when migrating
  • So I’m setting a link in docker-compose.yml and referencing the db container ip as ‘db’ using :

    - "JAVA_OPTS=-Dpostgres.host=db"

    However I’m getting the following error starting the microservice with docker:

    Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder ‘postgress.host’ in value “jdbc:postgresql://${postgress.host}:5432/docker”

    So basically this placeholder cannot be resolved, but normally docker-composed should take care of setting this system variable to point to the db container IP address right?

    What I’m doing wrong?

    Below the files involved:

    docker-compose.yml:

        version: "2"
    services:
      microservices:
          build: ./microservices
          container_name: microservices
          links:
            - db
            - consul
          environment:
            - "JAVA_OPTS=-Dpostgres.host=db"
      consul:
          image: consul
          container_name: consul
          ports:
                    - "8500:8500"
      db:
        image: postgres
        container_name: local-postgres9.6
        ports:
              - "5432:5432"
        environment:
          POSTGRES_PASSWORD: docker
          POSTGRES_USER: docker
    

    application.yml of the microservice:

        server:
      port: 8081
    
    project:
      jdbc:
        url: jdbc:postgresql://${postgres.host}:5432/docker
        driver: org.postgresql.Driver
        username: docker
        password: docker
    

  • docker daemon not connecting
  • Unable to mount specific paths as volumes
  • docker-compose get ID of a docker
  • Where i can find windows 64 bit box for vagrant
  • Can't change PHP variables in Joomla docker official container
  • Simple Flask application with debug set to True is not reloading in Docker?
  • One Solution collect form web for “Issue linking containers in Docker using Docker-compose”

    Try ${db.host}, according to the documentation:

    Containers for the linked service will be reachable at a hostname
    identical to the alias, or the service name if no alias was specified.

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