Docker Community Forums

Share and learn in the Docker community.

Linked container cannot be resolved on the service


(Luizkowalski) #1

I have a Java app that connects to a Postgres with Docker/Docker compose.
Here is the config for docker environment:

---

spring:
  profiles: docker

params:
  datasource:
    jdbcUrl: jdbc:postgresql://postgres/chathub

as you can see, the hostname is postgres, defined in the docker-compose.yml as follow:

postgres:
  image: postgres:9.5
  ports:
    - "5432:5432"
  environment:
    POSTGRES_PASSWORD: postgres
    POSTGRES_USER: postgres
    POSTGRES_DB: test
  volumes:
    - /var/lib/postgresql
app: 
  build: user/image
  ports:
    - "8080:8080"
  links:
    - redis
    - postgres
    - rabbitmq

when I try to import this stack to docker-cloud, I get this error when app is starting up

chathub-1 | 2016-05-13T13:16:49.780710069Z 	... 60 more
chathub-1 | 2016-05-13T13:16:49.780715135Z Caused by: java.net.UnknownHostException: postgres
chathub-1 | 2016-05-13T13:16:49.781300906Z 	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
chathub-1 | 2016-05-13T13:16:49.781682657Z 	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
chathub-1 | 2016-05-13T13:16:49.781858324Z 	at java.net.Socket.connect(Socket.java:589)
chathub-1 | 2016-05-13T13:16:49.782043587Z 	at org.postgresql.core.PGStream.<init>(PGStream.java:64)
chathub-1 | 2016-05-13T13:16:49.782240790Z 	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:133)
chathub-1 | 2016-05-13T13:16:49.782739855Z 	... 68 more

seems like the somehow, the links are missing in docker cloud. I tried with postgres-1 too and didn’t worked


(Luizkowalski) #2

I’m still facing this issue.
What I tried:

  • Remove service links on stackfile;
  • With service links removed, tried to use the hostname on the app (like postgres and postgres-1)

Nothing worked so far


(Dleblanc) #3

I’m having much the same issue here - sometimes a mix of redeployment / terminate and start seems to help. I wasn’t seeing any of this on Tutum.


(Viveksaini07) #4

Same issue here as well. Hostname is not getting resolved.


(Luizkowalski) #5

Hey guys
I fixed it NOT using the alpine image versions


(Viveksaini07) #6

Is there any way to make it work with alpine base image?


(Iteamnetworkdc) #7

If you use alpine:edge, it should fix DNS issues


(Vidsy.co (Charlie)) #8

The DNS fix has been merged from :edge into 3.4.

Reference: https://github.com/gliderlabs/docker-alpine/issues/165

So use alpine:3.4 as your base image.