title: Docker compose:
body: <p>For example, here is my project structure:</p>
  
  <pre><code>project
       |
       +-- docker-compose.yml
       |    
       +-- hq-backend
       |  +-- Dockerfile
       |  +-- .env.docker-compose
  </code></pre>
  
  <p>here is my docker compose file:</p>
  
  <pre><code>db:
    container_name: hq-db
    image: postgres:latest
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: user_name
      POSTGRES_PASSWORD: password
      POSTGRES_DB: db_name
  
  mongo:
    container_name: hq-mongo
    image: mongo:3.2.9
    tty: true
    stdin_open: true
    ports:
      - "27027:27027"
    volumes:
      - mongo:/data/db
  
  hq-backend:
    env_file:
      - ../hq-backend/.env.docker_compose
    build: ../hq-backend/
    dockerfile: Dockerfile
    ports:
      - "8686:8686"
    volumes:
      - ".:/webapp"
    links:
      - db
      - mongo
  </code></pre>
  
  <p>When I tried to run <code>docker-compose up</code>. I always meet this exception at the end:</p>
  
  <blockquote>
    <p>ERROR: for hq-backend  Cannot start service hq-backend: Cannot link to
    a non running container: /hq-mongo AS /project_hq-backend_1/mongo</p>
  </blockquote>
  
  <p>Here is my environment file:</p>
  
  <pre><code>ENV=dev
  DB_HOST=db
  DB_ADDRESS=db
  DB_PORT=5432
  POSTGRES_DB=db_name
  POSTGRES_USER=username
  POSTGRES_PASSWORD=password
  
  DB_MONGO_ADDRESS=mongo
  DB_MONGO_PORT=27027
  </code></pre>
  
  <p>This problem is only with mongo service, not db service. After that, if I tried to run <code>docker-compose up</code> again, no error found, but my <code>hq-backend</code> will throw exception because cannot connect to mongo db. In other word, I just meet this problem when rebuild <code>hq-backend</code> from scratch.</p>
  
  <p>Please tell me about this problem.</p>