21

Running the external volume sample yml from docker-compose v3 docs gives me the following error:

ERROR: Volume data declared as external, but could not be found. Please create the volume manually using `docker volume create --name=data` and try again.

This is the yml code:

version: '2'

services:
  db:
    image: postgres
    volumes:
      - data:/var/lib/postgresql/data

volumes:
  data:
    external: true

I`m running it on windows 10. Also tried to set the version to '3' but got the same error.

ash
  • 1,065
  • 1
  • 5
  • 20
ramiwi
  • 902
  • 2
  • 10
  • 28

1 Answers1

44

As the error message specifies, you need to create the volume by running:

docker volume create data

When you declare a volume as external in docker compose, it means that the volume has been previously created and you are just referencing it in the compose file.

OR

allow dockercompse to auto create the volume so just remove "external: true"

Chitrang
  • 5,097
  • 1
  • 35
  • 58
yamenk
  • 46,736
  • 10
  • 93
  • 87
  • 2
    Why can't the docker-compose command create it for you? I'm not understanding. If I want to pass a docker-compose.yml file to a friend, i dont want to have to tell them to run this create command. See what I mean? – djangofan Sep 29 '18 at 01:38
  • 9
    @djangofan to allow dockercompse to auto create the volume just remove `external: true` – yamenk Sep 29 '18 at 03:34
  • external: false, works like a charm! – KD.S.T. Jan 23 '22 at 14:11
  • 1
    by default Compose creates a volume for `data` where the name is prefixed with your project name. If you want it to just be called `data`, declare it with `external: true` – Luke Schoen Jan 03 '23 at 20:52