How to use mounted non-system drive as storage for database Docker container?

59 views Asked by At

I'm writing as a beginner docker user.

My Objective:

  • To run a couchdb container on my local machine simply using the image found at https://github.com/apache/couchdb-docker/blob/main/README.md
  • Use a pre-mounted, non-boot SATA HDD as the device for database storage. To my understanding so far, a bind mount is an easy solution as I should be able to specify the (from the host's perspective) mount source path. However, I'm open to using Volumes as well.

Docker and System Info

  • Linux fedora 6.6.6-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC
  • Docker Desktop v4.26.1 using defaults

Run Script

Before beginning, the device is confirmed to be mounted in the host filesystem at the designated path.

#!/usr/bin/env bash
docker run --name couchdb \
    -p 5984:5984 \
    -v /run/media/username/devicelabel/Docker/couchdb/mount/data:/opt/couchdb/data \
    -e COUCHDB_USER=adminname \
    -e COUCHDB_PASSWORD=adminpassword \
    -d couchdb && \

# Wait for container
sleep 5 && \

# Create required databases
curl -X PUT http://adminname:[email protected]:5984/_users && \
curl -X PUT http://adminname:[email protected]:5984/_replicator && \
curl -X PUT http://adminname:[email protected]:5984/_global_changes

Result

Running this script results in what appears to be a successful binding where data is persisted whenever I delete the container and rebuild.

The problem: the data isn't stored in the specified mount point, on the host, at /run/media/username/devicelabel/Docker/couchdb/mount/data; I do not know where the data is being persisted between container builds, however restarting Docker Desktop purges the data.

Inspect

Here are some snippets from docker inspect:

Config.Volumes (I'm assuming the default Volume in the dockerfile)

            "Volumes": {
                "/opt/couchdb/data": {}
            },

Mounts

        "Mounts": [
            {
                "Type": "bind",
                "Source": "/run/media/username/devicelabel/Docker/couchdb/mount/data",
                "Destination": "/opt/couchdb/data",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],

Additional

Replacing the -v option with something like

...
--mount type=bind,source=/run/media/username/devicelabel/Docker/couchdb/mount/data,target=/opt/couchdb/data \
...

Results in an error, and failure to run:

docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /run/media/username/devicelabel/Docker/couchdb/mount/data.
0

There are 0 answers