skip to Main Content

This is a docker-compose.yml file.
When I am running the docker-compose-up command it will through an error.
looks like **services. volumes must be a mapping **
`

version: '3.9'
services:
  zookeeper:
    container_name: zookeeper
    image: wurstmeister/zookeeper
    ports:
      - '2181:2181'
  kafka:
    container_name: kafka
    image: wurstmeister/kafka
    ports:
      - '9092:9092'
  volumes:
    - ./data/kafka: /var/run/docker.sock
  environment: 
    KAFKA_ADVERTISED_HOST_NAME: kafka 
    KAFKA_ZOOKEEPER_CONNECT=zookeeper: 2181
  mongo:
    container_name: mongo
    image: mongo
    ports:
      - '27017:27017'
    volumes:
      - './data/mongo:/data/db'
  app1:
    container_name: app1
    build: ./app1
    ports:
      - '8080:8080'
    volumes:
      - ./app1:/app
    environment:
      PORT: 8080
      MONGO_URL: 'mongodb://mongo:27017/app1'
      KAFKA_BOOTSTRAP_SERVERS: 'kafka:9092'
      KAFKA_TOPIC: topic1
    depends_on:
      - mongo
      - kafka
  app2:
    container_name: app2
    build: ./app2
    ports:
      - '8081:8080'
    volumes:
      - ./app2:/app
    environment:
      PORT: 8081
      MONGO_URL: 'mongodb://mongo:27017/app2'
      KAFKA_BOOTSTRAP_SERVERS: 'kafka:9092'
      KAFKA_TOPIC: topic1
    depends_on:
      - mongo
      - kafka

`

basically The docker compose up command aggregates the output of each container.

2

Answers


  1. The docker-compose reference v3 and more specifically the usage of volumes in Docker specifies the use of named volumes in the first parameter and not path:

    -v or --volume: Consists of three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field is not immediately obvious.

    • In the case of named volumes, the first field is the name of the volume, and is unique on a given host machine. For anonymous volumes, the first field is omitted.
    • The second field is the path where the file or directory are mounted in the container.
    • The third field is optional, and is a comma-separated list of options, such as ro. These options are discussed below.

    […]

    It means you can’t use directly a path in the volumes parameter.

    This question (How do I mount a host directory as a volume in docker compose — @Amin Shah Gilani) talks about your issue. You should take inspiration of the most populary answer from it(@Yuci).

    Login or Signup to reply.
  2. The volumes being used needs to be mapped in the docker compose.

    In your docker file, add something like follows to map the volumes and do it for each volume you are trying to map.

    services:
      app2:
        container_name: app2
        build: ./app2
        ports:
          - '8081:8080'
        volumes:
          - myapp2:/app # ./app2 has been updated to myapp2, myapp2 is the volume name
        environment:
          PORT: 8081
          MONGO_URL: 'mongodb://mongo:27017/app2'
          KAFKA_BOOTSTRAP_SERVERS: 'kafka:9092'
          KAFKA_TOPIC: topic1
        depends_on:
          - mongo
          - kafka
    
    volumes:
      myapp2:
      # add the other volumes mapped here
    

    More info on docker volume.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search