Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-compose: no declaration was found in the volumes section #67

Open
Edke opened this issue Oct 1, 2016 · 38 comments
Open

docker-compose: no declaration was found in the volumes section #67

Edke opened this issue Oct 1, 2016 · 38 comments

Comments

@Edke
Copy link

Edke commented Oct 1, 2016

Hello.

Trying to spin dvol, but encounter problems:

docker-compose.yml:

version: "2"
services:
  web:
    container_name: web-dev
    build:
      context: .
      dockerfile: services/development/web/Dockerfile
    links:
      - db
      - cache
    depends_on:
      - db
      - cache

  queue:
    container_name: queue-dev
    image: queue:latest
    entrypoint: python2.7 manage.py rqworker
    links:
      - db
      - cache
    depends_on:
      - db
      - cache

  db:
    container_name: db-dev
    image: db:latest
    volumes:
      - "db:/var/lib/postgresql/data"
    volume_driver: dvol

  cache:
    container_name: cache-dev
    image: redis:latest

spinning docker-compose:

$ docker-compose up
ERROR: Named volume "db:/var/lib/postgresql/data:rw" is used in service "db" but no declaration was found in the volumes section.
$ docker volume ls
list dvol: VolumeDriver.List: 
<html>
  <head><title>404 - No Such Resource</title></head>
  <body>
    <h1>No Such Resource</h1>
    <p>No such child resource.</p>
  </body>
</html>

DRIVER              VOLUME NAME
local               00894d48cfdd9d2493378e0b12413294756a20142cc8921b137881c5c6aecfc4
local               010b05964a81ad4219a9f3c05d55a24f9fefec4644a360498fb3ba064470290c
$ docker info
Containers: 32
 Running: 1
 Paused: 0
 Stopped: 31
Images: 195
Server Version: 1.12.1
Storage Driver: devicemapper
 Pool Name: docker-254:1-1054363-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 107.4 GB
 Backing Filesystem: ext4
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 17.87 GB
 Data Space Total: 107.4 GB
 Data Space Available: 4.271 GB
 Metadata Space Used: 20.53 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.127 GB
 Thin Pool Minimum Free Space: 10.74 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Deferred Deletion Enabled: false
 Deferred Deleted Device Count: 0
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.133 (2016-08-15)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local dvol
 Network: bridge host null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 4.7.2-1-ARCH
Operating System: Arch Linux
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 11.33 GiB
Name: thingol
ID: CFYC:6PZ7:X5EQ:U6CL:UVRT:NAYB:FART:Y3HS:Z4UE:UPRU:7EM6:XP25
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
 127.0.0.0/8
@chanes-probe
Copy link

I'm not using compose but am having the same output from

# docker volume ls

list dvol: VolumeDriver.List: 
<html>
  <head><title>404 - No Such Resource</title></head>
  <body>
    <h1>No Such Resource</h1>
    <p>No such child resource.</p>
  </body>
</html>

DRIVER              VOLUME NAME
local               006b52bbe8e4f33a56ab535fcf56fa2f30bf0668121519071f60b768e45e0b62
local               69f6e1bc35c3421153546c2effcf037f403a6eb44cc0ef10e4ff447fa5235076
local               8b6da2ceda666d70b67d7ae539d7073a6a2dbb4bb43a5d5e211dd54e35fe7b33
local               b823b18ed7954b65cf751c6d9a73446750070771006f9d4a33887551bf54182c

It was working fine surviving reboots. The only subsequent docker commands I executed were to init swarm and create an overlay network.

@tiagotakahashi
Copy link

@Edke do you encontered a solution?

@Edke
Copy link
Author

Edke commented Dec 20, 2016

@tiagotakahashi sorry no, didnt find solution, not using dvol

@jlbarat
Copy link

jlbarat commented Mar 9, 2017

Have you try to make relative links (eg. ./)?

@jstray
Copy link

jstray commented Apr 14, 2017

Same problem:

version: '3'

services:

  web:
    image: jonathanstray/cjworkbench
    container_name: cjw-web
    volumes:
      - data:/cjworkbench
    ports:
      - "8000:8000"
    command: /cjworkbench/start-prod.sh

gives

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

@jstray
Copy link

jstray commented Apr 14, 2017

Ah, I see, in both cases above the problem is we have no volumes section in docker-compose.yml, just as the error message suggests: https://docs.docker.com/compose/compose-file/#volume-configuration-reference

@sleepy-zeo
Copy link

ERROR: Named volume "data:/cjworkbench:rw" is used in service "web" but no declaration was found in the volumes section.
use ./data instead of data and make sure directory ./data exists.

@Arkanius
Copy link

When you use a named volume, like "data:/cjworkbench:rw" you must declare it at the docker-compose file (at the end as a good pratice). Here's an example:

volumes:
data:
driver: local

If you just want to use the path "data" you have to specify all address of it. Here's an exemple:
./data:cjworkbench:rw/

@alanteals
Copy link

alanteals commented Nov 6, 2017

I had the same problem and I just follow the instructions from @jstray adding the volumes section at the end of my docker-compose file.

volumes:
    volume-name:
    driver: local  # is already local by default

@vionemc
Copy link

vionemc commented Nov 26, 2017

I also get the same problem. I am not sure how to debug it, but this is the yml

version: '2'

services:
    haproxy:
        image: haproxy:1.7
        ports:
            # stats
            - "8036:8036"

            # splash
            - "8050:8050"
        links:
            - splash0
            - splash1
            - splash2
        volumes:
            - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro

    splash0:
        image: scrapinghub/splash:3.0
        command: --max-timeout 3600 --slots 5 --maxrss 3000 --verbosity 1
        expose:
            - 8050
        mem_limit: 4200m
        memswap_limit: 5400m
        restart: always
        links:
            - tor
        volumes:
            - ./proxy-profiles:/etc/splash/proxy-profiles:ro
            - ./filters:/etc/splash/filters:ro

    splash1:
        image: scrapinghub/splash:3.0
        command: --max-timeout 3600 --slots 5 --maxrss 3000 --verbosity 1
        expose:
            - 8050
        mem_limit: 4200m
        memswap_limit: 5400m
        restart: always
        links:
            - tor
        volumes:
            - ./proxy-profiles:/etc/splash/proxy-profiles:ro
            - ./filters:/etc/splash/filters:ro

    splash2:
        image: scrapinghub/splash:3.0
        command: --max-timeout 3600 --slots 5 --maxrss 3000 --verbosity 1
        expose:
            - 8050
        mem_limit: 4200m
        memswap_limit: 5400m
        restart: always
        links:
            - tor
        volumes:
            - ./proxy-profiles:/etc/splash/proxy-profiles:ro
            - ./filters:/etc/splash/filters:ro


    
    tor:
        image: jess/tor-proxy
        expose:
            - 9050
        logging:
            driver: "none"
        restart: always

@vionemc
Copy link

vionemc commented Nov 26, 2017

I've tried adding this code below at the end:

volumes:
    filters:
        driver: local
    proxy-profiles:
        driver: local

It doesn't work

@lc-thomas
Copy link

Using ./xxxx instead of xxxx solved this issue for me.

@cmardonespino
Copy link

I create a volume to my postgres container, but I cant access to it for permission ... Someone can help me?

@prat3ik
Copy link

prat3ik commented May 9, 2018

Hi @Edke ,

You should add volume section in your .yml file, please refer below code:

version: "2"
services:
web:
container_name: web-dev
build:
context: .
dockerfile: services/development/web/Dockerfile
links:
- db
- cache
depends_on:
- db
- cache

queue:
container_name: queue-dev
image: queue:latest
entrypoint: python2.7 manage.py rqworker
links:
- db
- cache
depends_on:
- db
- cache

db:
container_name: db-dev
image: db:latest
volumes:
- "db:/var/lib/postgresql/data"
volume_driver: dvol

cache:
container_name: cache-dev
image: redis:latest

volumes:
db:

@wallrj
Copy link

wallrj commented May 9, 2018

Hey everyone, dvol is no longer maintained. You might try https://github.com/dotmesh-io/dotmesh instead.

@Noumcreation
Copy link

@prat3ik I wonder where you declare the path to "db" ?

@imohamedibrahim
Copy link

Try giving absolute path it resolves for me!

@lukyer
Copy link

lukyer commented Dec 23, 2018

You can use relative path but make sure you prepend ./
So data/video/:/mnt/video/:ro is not working but ./data/video/:/mnt/video/:ro is OKAY.

@Cerebro92
Copy link

Cerebro92 commented Jan 19, 2019

Docker has different type of storages. when you give absolute path, it uses docker Bind Mounts while if you specify volume :</where/it/mounts/in/container> in this format, it uses Docker Named volume Storage.

https://docs.docker.com/storage/bind-mounts
https://docs.docker.com/storage/volumes

If you want to use named volumes, you must specify it in docker-compose volume section.
https://docs.docker.com/compose/compose-file/#volume-configuration-reference

@mrroot5
Copy link

mrroot5 commented Feb 20, 2019

If you want to bind a docker container folder with a host folder (like usual) then use bind instead of volume. I give you an example for postgres:

services:
  db:
    image: postgres
    volumes:
      - type: bind
        source: /host_folder/postgres_data
        target: /var/lib/postgresql/data/

Here is the official documentation example with static.

@kenjioi
Copy link

kenjioi commented May 1, 2019

Using ./xxxx instead of xxxx solved this issue for me.

Thank you K-marad, It's worked for me, like..
api → ./api
in .yml.

@iarechagaMM
Copy link

I've tried adding this code below at the end:

volumes:
    filters:
        driver: local
    proxy-profiles:
        driver: local

It doesn't work

Add it at the top

@Jean-Baptiste-Lasselle
Copy link

Jean-Baptiste-Lasselle commented May 29, 2019

Hi guys, I have something here that might lead to explanation.

Here is an example I just tried, using only Docker, no docker-compose :

jbl@poste-devops-typique:~/.tungunska/.awx/provision$ docker run -itd --name cerbotiii --restart unless-stopped --entrypoint sh -e path=$tungunska_path -v $data_path:$tungunska_path certbot/certbot
docker: Error response from daemon: create ./data/certbot: "./data/certbot" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.

I here mention the environment :

export data_path=./data/certbot
export tungunska_path=/etc/letsencrypt/live

jbl@poste-devops-typique:~/.tungunska/.awx/provision$ echo "docker run -itd --name cerbotiii --restart unless-stopped --entrypoint sh -e path=$tungunska_path -v $data_path:$tungunska_path certbot/certbot"
docker run -itd --name cerbotiii --restart unless-stopped --entrypoint sh -e path=/etc/letsencrypt/live -v ./data/certbot:/etc/letsencrypt/live certbot/certbot


export domains=(google.io waffle.jp ebay.com) # guess what i was doing

Alright, so, with that docker run command, I still get the error :

jbl@poste-devops-typique:~/.tungunska/.awx/provision$ docker run -itd --name cerbotiii --restart unless-stopped --entrypoint sh -e path=$tungunska_path -v $data_path:$tungunska_path certbot/certbot
docker: Error response from daemon: create ./data/certbot: "./data/certbot" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.

Now, let's Highlight error message :

"./data/certbot" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.

So let's go and use absolute path :

jbl@poste-devops-typique:~/.tungunska/.awx/provision$ docker run -itd --name cerbotiii --restart unless-stopped --entrypoint sh -e path=/etc/letsencrypt/live -v $(pwd)/data/certbot:/etc/letsencrypt/live certbot/certbot
e36e85e0b311b0b434874b6771047d508b37882270d08a8ab79e157425293f07
jbl@poste-devops-typique:~/.tungunska/.awx/provision$ 

So there you go, it works.

Docker Compose

Nevertheless, like many others, I have many times experienced (so wont bother providing example) mapping bind mounted volumes to Docker containers using relative path, but recently exprienced I can't use an env. variable declared for instance in a ./.env file, and referenced into a docker-compose file.

Well after all, Maybe I will provide an example, some time later.

Thank you all for your remarks, and examples.

@enderandpeter
Copy link

enderandpeter commented Jun 24, 2019

I ran into this very issue myself. It is entirely possible to specify a docker volume name, rather than a path, in the short syntax of the volume definition. But if you use a volume name in such a way, you must also specify the name in a top-level volumes: mapping, so what you want is this:

version: "2"
services:
  web:
    container_name: web-dev
    build:
      context: .
      dockerfile: services/development/web/Dockerfile
    links:
      - db
      - cache
    depends_on:
      - db
      - cache

  queue:
    container_name: queue-dev
    image: queue:latest
    entrypoint: python2.7 manage.py rqworker
    links:
      - db
      - cache
    depends_on:
      - db
      - cache

  db:
    container_name: db-dev
    image: db:latest
    volumes:
      - "db:/var/lib/postgresql/data"
    volume_driver: dvol

  cache:
    container_name: cache-dev
    image: redis:latest

volumes:
  db:

Note that last top-level volumes setting which contains a mapping of a volume name that one of the services is expected to use.

@MrIceman
Copy link

MrIceman commented Oct 29, 2019

db:
container_name: db-dev
image: db:latest
volumes:
- "db:/var/lib/postgresql/data"
volume_driver: dvol

your volume declaration should not be one string, try
db:/var/lib/postgresql/data

and add at the bottom of your yml file

volumes:
db:

@VadyaZombie
Copy link

VadyaZombie commented Nov 18, 2019

I came here by chance looking for an answer to another problem. When I was looking for a solution to my problem, I had a similar error.

My ploblem:

FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
HINT:  The server must be started by the user that owns the data directory.

If you, like me, have not been helped by the setting of a relative path. Then if you look at the message above and do as you see it in the example, it all worked great. My example before and after:

before :

version: "3"
services:
  test_db:
    image: postgres:11.5-alpine
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: test
      POSTGRES_PASSWORD: test
      POSTGRES_DB: testdb
    volumes:
      - "./dbdata:/var/lib/postgresql/data"
# the same result if:
#   volumes:
#    - ./dbdata:/var/lib/postgresql/data

# volumes:
#    dbdata:

after :

version: "3"
services:
 test_db:
    image: postgres:11.5-alpine
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: test
      POSTGRES_PASSWORD: test
      POSTGRES_DB: testdb
    volumes:
      - dbdata:/var/lib/postgresql/data/
  
volumes:
  dbdata:

@ramonrrp
Copy link

worked for me with absolute path

@pparasuram
Copy link

This thread seems to be of no use, amazed that people say they have a solution but do not give a clear example of what fixed the volume error

Prakash

@enderandpeter
Copy link

@pparasuram It looks like the only problem was that the original docker-compose.yml was missing a top-level volumes key that named the volume to be used in the shorthand syntax db:/var/lib/postgresql/data. With such a setting, the db volume name needs to be listed as a key under volumes:. It has also been suggested that removing the quotes around that string might help.

@pparasuram
Copy link

@pparasuram It looks like the only problem was that the original docker-compose.yml was missing a top-level volumes key that named the volume to be used in the shorthand syntax db:/var/lib/postgresql/data. With such a setting, the db volume name needs to be listed as a key under volumes:. It has also been suggested that removing the quotes around that string might help.

Thanks so much @enderandpeter

@eranthaWELIKALA
Copy link

Using ./xxxx instead of xxxx solved this issue for me.

This solved the issue for me.

@SyedaAyesha1000
Copy link

Using ./xxxx instead of xxxx solved this issue for me.

This works for me too

csjiang added a commit to AudiusProject/audius-protocol that referenced this issue Nov 5, 2021
csjiang added a commit to AudiusProject/audius-protocol that referenced this issue Nov 5, 2021
@maciej-wakula-opuscapita

This is due to

container:
  volumes:
    <object>:<target>

It should be either:

container:
  volumes:
    ./<object>:<target>

or

container:
  volumes:
    /full/path/to/<object>:<target>

or

container:
  volumes:
    <name>:<target>
volumes:
  name:
    driver: local

@franco-cunza
Copy link

If you want to use named volumes you should follow this one: https://docs.docker.com/storage/volumes/#use-a-volume-with-docker-compose

@StephaneGenet
Copy link

StephaneGenet commented Jul 15, 2022

Named volumes can be used by multiple services.
If u need to name it using for ex : mongo-data:db/data

They need to be declared (out of the service indentation) at the end of the docker-compose file like that :

  node-app-data:
    image: mongo
    environment:
      - MONGO_INITDB_ROOT_USERNAME=usr
      - MONGO_INITDB_ROOT_PASSWORD=psswd
    volumes:
      - mongo-db:/data/db

volumes:
  mongo-db:

@ranoaritsiky
Copy link

make sure that volume exist

@victor-teran-rs-old
Copy link

ERROR: Named volume "data:/cjworkbench:rw" is used in service "web" but no declaration was found in the volumes section. use ./data instead of data and make sure directory ./data exists.

Example with SQLServer

version: '3'
services:
  server:
    container_name: "${LOCALSTACK_DOCKER_NAME}-server"
    image: mcr.microsoft.com/mssql/server:2017-CU31-ubuntu-18.04
    ports:
      - 1433:1433
    environment:
      - ACCEPT_EULA="Y"
      - MSSQL_SA_PASSWORD=A12345!ab
    volumes:
      - "./data/yardi-mssql/data:/var/opt/mssql/data"
      - "./data/yardi-mssql/log:/var/opt/mssql/log"
      - "./data/yardi-mssql/secrets:/var/opt/mssql/secrets"
 volumes:
  data:

The folder `data' must exist within the same level

@Kordedekehine
Copy link

I had same error but i was able to solve it following instructions from this thread. This is how my compose yml looks like now

version: '3.1'
services:
dbpostgresql:
image: "postgres:12"
container_name: dbpostgresql
networks:
- el-pgsql
ports:
- "5432:5432"
volumes:
- db:/var/lib/postgresql/data
environment:
POSTGRES_DB: loll
POSTGRES_PASSWORD: loll

app:
container_name: e-l
image: e-l
networks:
- el-pgsql
build: ./
ports:
- "8080:8080"
depends_on:
- dbpostgresql
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://dbpostgresql:5432/loll
- SPRING_DATASOURCE_USERNAME=loll
- SPRING_DATASOURCE_PASSWORD=loll
- SPRING_JPA_HIBERNATE_DDL_AUTO=update

networks:
el-pgsql:
volumes:
db:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests