Skip to content

Query About Creating Volumes Without Services in Docker Compose v2 #10930

@ghost

Description

Description

In Docker Compose v1, I was able to create volumes independently using the following syntax:

version: '3.2'
volumes:
  volume1:
    driver: local
    name: "volume1"

However, upon migrating to Docker Compose v2, I attempted to use the same approach. Unfortunately, I encountered an error message "no service selected." It seems that the behavior has changed in v2 regarding how volumes are define

I'm looking for advice on how to create volumes in Docker Compose v2  without associating them with any specific service in Docker Compose v2. This was possible in v1, and I'm curious whether there's a workaround or new syntax in v2 that achieves the same result.

Steps To Reproduce

  1. Up Docker Compose with the YAML file using v1 syntax to define volumes.
    Use the following YAML code:
version: '3.2'
volumes:
  volume1:
    driver: local
    name: "volume1"
  1. Attempt to use the same file in Docker Compose v2 environment.
  2. Observe the "no service selected" error.

Compose Version

Docker Compose version v2.20.3

Docker Environment

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx

Server:
 Containers: 16
  Running: 16
  Paused: 0
  Stopped: 0
 Images: 63
 Server Version: 23.0.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: journald
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2456e983eb9e37e47538f59ea18f2043c9a73640
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.1.0-11-amd64
 Operating System: Debian GNU/Linux 12 (bookworm)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.27GiB
 Name: DEB-NUC11PAH-G6PA250003P9
 ID: 09e27f09-76c5-45dc-b50d-bb2b05611aac
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: true
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Default Address Pools:
   Base: 172.128.0.1/9, Size: 16
   Base: fdd0:df31:dff5::1/104, Size: 112

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions