I am building a java spring mvc application in docker and dockefile build involves interacting with postgres container. Whenever i run docker-compose up the step in dockerfile which interacts with the postrges sometimes fails with an exception 
psql: could not translate host name "somePostgres" to address: Name or service not known FAILED
FAILURE: Build failed with an exception.
DockerCompose file:
abcdweb:
  links:
  - abcdpostgres
  build: .
  ports:
  - "8080:8080"
  volumes:
  - .:/abcd-myproj
  container_name: someWeb
abcdpostgres:
  image: postgres
  environment:
  - POSTGRES_PASSWORD=postgres
  - POSTGRES_USER=postgres
  container_name: somePostgres
The somePostgres seems to start very quickly and There is no late loading of postgres container problem. Currently i am running this in virtual box created by docker-machine. Unable to get error as it's not persistent.
PS: Added Dockerfile
FROM java:7
RUN apt-get update && apt-get install -y postgresql-client-9.4
ADD . ./abcd-myproj
WORKDIR /abcd-myproj
RUN ./gradlew build -x test 
RUN sh db/importdata.sh
CMD ./gradlew jettyRun
 
     
     
    