Skip to content

Instantly share code, notes, and snippets.

@natanlao
Last active August 9, 2021 19:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natanlao/cd1974239339c949e434ebee2d313ecb to your computer and use it in GitHub Desktop.
Save natanlao/cd1974239339c949e434ebee2d313ecb to your computer and use it in GitHub Desktop.
docker-compose: no declaration was found in the volumes section

If, when doing something like docker-compose up, you run into an error like this:

ERROR: Named volume "server/db:/usr/share/nginx/html/db:rw" is used in service "web" but no declaration was found in the volumes section.

You're missing a leading ./, so, for example:

volumes:
 - 'server/db:/usr/share/nginx/html/db'

should read

volumes:
 - './server/db:/usr/share/nginx/html/db'

This example assumes that you want to map a host directory ./server/db/ to a container directory /usr/share/nginx/html/db, not create a named volume server/db.

@ordidaad
Copy link

ordidaad commented Aug 7, 2021

No its not, if you add ./ to leading then docker will create new directory on the context, so it will be completely new volume and diffrent from that named volume.

you should simply add this section to the compose file

`
volumes:
volume-name-here:

`

@natanlao
Copy link
Author

natanlao commented Aug 7, 2021

No its not, if you add ./ to leading then docker will create new directory on context, so it will be completely new volume and diffrent from that named volume.

Yes, to clarify, that was my intent (i.e. I wanted to map the local directory ./server/db to /usr/share/nginx/html/db in the container, not a named volume server/db)

@ordidaad
Copy link

ordidaad commented Aug 7, 2021

okay, sorry, i thought you are intended to use a named volume.

@natanlao
Copy link
Author

natanlao commented Aug 7, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment