ClusterHQ / dvol

Version control for your development databases in Docker.
https://clusterhq.com/
Apache License 2.0
250 stars 17 forks source link

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

Open Edke opened 8 years ago

Edke commented 8 years ago

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 commented 8 years ago

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 commented 7 years ago

@Edke do you encontered a solution?

Edke commented 7 years ago

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

jlbarat commented 7 years ago

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

jstray commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

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

It doesn't work

lc-thomas commented 6 years ago

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

cmardonespino commented 6 years ago

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

prat3ik commented 6 years ago

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:

volumes: db:

wallrj commented 6 years ago

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

Noumcreation commented 6 years ago

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

imohamedibrahim commented 6 years ago

Try giving absolute path it resolves for me!

lukyer commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

worked for me with absolute path

pparasuram commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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

This solved the issue for me.

SyedaAyesha1000 commented 2 years ago

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

This works for me too

maciej-wakula-opuscapita commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

make sure that volume exist

victor-teran-rs-old commented 1 year ago

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 commented 1 year ago

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:

networks: el-pgsql: volumes: db: