Docker compose:

For example, here is my project structure:

project
     |
     +-- docker-compose.yml
     |    
     +-- hq-backend
     |  +-- Dockerfile
     |  +-- .env.docker-compose

here is my docker compose file:

  • Can't connect container docker from Macos
  • What are the minimum requirements of neo4j?
  • Run Docker commands in Jenkins Shell
  • adding jenkins user to docker group usermod vs gpasswd
  • Vagrant with Docker Provider fails with rsync over ssh
  • Set execution timeout limit while creating docker
  • 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
    

    When I tried to run docker-compose up. I always meet this exception at the end:

    ERROR: for hq-backend Cannot start service hq-backend: Cannot link to
    a non running container: /hq-mongo AS /project_hq-backend_1/mongo

    Here is my environment file:

    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
    

    This problem is only with mongo service, not db service. After that, if I tried to run docker-compose up again, no error found, but my hq-backend will throw exception because cannot connect to mongo db. In other word, I just meet this problem when rebuild hq-backend from scratch.

    Please tell me about this problem.

  • “Memory used” metric: Go tool pprof vs docker stats
  • mysql with Exited(1) from docker
  • dotnet core on docker performance
  • Local development and swarm service image update
  • How to run AWS ECS Task overriding environment variables
  • docker run with -p and a single port (instead of mapping)
  • 2 Solutions collect form web for “Docker compose:”

    Remove tty and stdin_open options from docker-compose file.
    i suppose that it’s messing with how docker-compose is handling containers.
    if You want to execute commands inside mongo container then after compose up just login into it using:
    docker exec -t -i hq-mongo /bin/bash

    By the way – You may consider to use docker-compose version 2 or 3 and depends_on instead of links
    https://docs.docker.com/compose/compose-file/compose-file-v2/

    Try adding depends_on to hq-backend at the same level as links. For example:

    depends_on:
      - mongo
      - db
    links:
      - db
      - mongo
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.