I have the following docker-compose file starting the first time the containers start as expected:
version: "3.8"
volumes:
mongodb-data:
name: mongodb-data
networks:
mongodb_network:
name: mongodb_network
services:
mongodb:
image: mongo:4.4.5-bionic
container_name: mongodb
environment:
- MONGO_INITDB_DATABASE: provider
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=pass12345
volumes:
- mongodb-data:/data/db
networks:
- mongodb_network
ports:
- 27017:27017
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongo 10.10.10.60:27017/test --quiet
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
mongo-express:
image: mongo-express:0.54.0
container_name: mongo-express
environment:
- ME_CONFIG_MONGODB_SERVER=mongodb
- ME_CONFIG_MONGODB_ENABLE_ADMIN=true
- ME_CONFIG_MONGODB_ADMINUSERNAME=root
- ME_CONFIG_MONGODB_ADMINPASSWORD=pass12345
- ME_CONFIG_BASICAUTH_USERNAME=admin
- ME_CONFIG_BASICAUTH_PASSWORD=admin123
volumes:
- mongodb-data
depends_on:
- mongodb
networks:
- mongodb_network
ports:
- 8081:8081
healthcheck:
test: wget --quiet --tries=3 --spider http://admin:admin123@10.10.10.60:8081 || exit 1
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
After the restart the containers it complains:
ERROR: for mongo-express Cannot create container for service mongo-express: invalid volume specification: '33e23b77e1a84955e2180d502bdcf1f34589ddd1a99172629e968f10d8208d3d:mongodb-data:rw': invalid mount config for type "volume": invalid mount path: 'mongodb-data' mount path must be absolute
ERROR: for mongo-express Cannot create container for service mongo-express: invalid volume specification: '33e23b77e1a84955e2180d502bdcf1f34589ddd1a99172629e968f10d8208d3d:mongodb-data:rw': invalid mount config for type "volume": invalid mount path: 'mongodb-data' mount path must be absolute
ERROR: Encountered errors while bringing up the project.
What is missing?
The volumes:
block in the mongo-express
service is confusing Compose, and you should be able to delete it.
volumes:
- mongodb-data
Without a colon :
in the volume specification, this looks like it's trying to create an anonymous volume; but that generally needs an absolute path. Compose will preserve these anonymous volumes across restarts, but the second time you try to run docker-compose up
it sends the Docker API a mount string that doesn't really make sense in the API.
This looks like you're trying to mount the database's underlying data into an application that talks to the database's API. You don't need that, and you can just delete this volumes:
block.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.