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
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: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).
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.
More info on docker volume.