How to restore Docker volumes on a different host?

My idea was to:

  1. tar the volumes wikijs_wikijs_config and wikijs_wikijs_data from the source host after shutting down the container
  2. scp the tar to the new host
  3. create a Docker volume on the new host
  4. finally untar the copied tar-file into the newly created docker volume
  5. start the container on the new host with Docker compose

Unfortunately when powering up the container with docker compose I get the following error:

WARN[0000] volume “wikijs_wikijs_config” already exists but was not created by Docker Compose. Use external: true to use an existing volume
WARN[0000] volume “wikijs_wikijs_data” already exists but was not created by Docker Compose. Use external: true to use an existing volume

What does this error message exactly mean and what can I do?

Thanks a lot for helping me out.

It means that you created the volume manually not using Docker Compose, but Docker Compose will not be able to reuse it if it was not the one that created it. One solution is mentioned in the error message. You can add it to the volume definition in the compose file.

You could use compose to create the volume by running “docker compose up”, stopping the project and overriding the content of the created volumes, or you can manually set the labels that helps compose recognize the volume as created by compose

docker volume create compose_data2 \
  --label com.docker.compose.project=compose

The value of the label should be the actual compose project name. You could add the rest of the labels too, but this single label is enough to let compose use the volume. You can inspect a volume created by compose to see what other labels exist, but here is an output from my machine

docker volume inspect compose_data
[
    {
        "CreatedAt": "2025-06-18T18:18:12Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.config-hash": "bdac2a6221b3c822ff2c1107cfd3a0af7a8edf4ddef0ff8d7116285754a7f4e7",
            "com.docker.compose.project": "compose",
            "com.docker.compose.version": "2.36.1",
            "com.docker.compose.volume": "data"
        },
        "Mountpoint": "/var/lib/docker/volumes/compose_data/_data",
        "Name": "compose_data",
        "Options": null,
        "Scope": "local"
    }
]

Thanks a lot rimelek for your fast reply and help that made me think about it again.
I changed my workflow completely because nowadays I prefer bind mounts over volumes so I:

  1. restored the content of the archived volumes to different directories on the new host
  2. changed the owner of the new directories acordingly
  3. finally changed my docker-compose.yaml to use bind mounts instead of volumes
  4. after powering up the container everything now works like a charm

Maybe this helps other LINUX-Noobs like me.

1 Like

Yes, compared to local volumes, a bind mount could often be better. There are exceptions like when using Docker Desktop on Windows without WSL or when you want data to be copied from an image to the volume without worrying about permissions, but since you already had the content in tar files, a bind mount could work well on Linux.

Thank you for sharing your conclusion.