user8453362
user8453362

Reputation:

ERROR: Named volume "mongodb:/data/db:rw" is used in service "mongo" but no declaration was found in the volumes section

I just start learning Docker recently. Trying to set up a service that stores database.

Here's my docker-compose.yml:

version: "3.7"

services:
  mongo:
    image: mongo
    ports:
    - 27018:27017
    volumes:
    - mongodb:/data/db

volumes:
  mongo:

As I run docker-compose up ., I got this error:

ERROR: Named volume "mongodb:/data/db:rw" is used in service "mongo" but no declaration was found in the volumes section.

And I did create my named volume mongodb outside. Running docker volume ls would give me:

DRIVER    VOLUME NAME
local     mongodb

Any ideas? Thanks alot.

Upvotes: 9

Views: 13239

Answers (1)

Kevin KOUOMEU
Kevin KOUOMEU

Reputation: 370

For named volumes you should have a "volumes" key on a same level as "services", and any named volumes you are using in your services have to be listed under the "volumes" key (where you missed).

in your case :

version: "3.7"

services:
  mongo:
    image: mongo
    ports:
    - 27018:27017
    volumes:
    - mongodb:/data/db

volumes:
  mongodb:

Just a reminder : anonymous volumes, and bind mounts don't need to be specified here.

hope this helped you :)

Upvotes: 16

Related Questions