I am trying to create a docker volume of mongo that can be used even after a container is deleted. The volume works with the command
docker run -d --name mongo-local -p 27017:27017 -v mongo-local:/data/db mongo.
However when I try to use the mount command
docker run -d --name mongo-local -p 27017:27017 --mount source=mongo-local,target=/data/db mongo
it shows the following error
Error response from daemon: invalid mount config for type "volume": invalid mount path: 'C:/Program Files/Git/data/db' mount path must be absolute.
See 'docker run --help'.
I already have a volume created with the name mongo-local
so that's not an issue. Why am I facing the error?
Edit:
Tried the answer of @BMitch, but still the same error.
The first issue is Git Bash converting the path. It is trying to change /data/db
to a relative path under the Git directories. To disable that behavior in Git Bash, you can add a second leading slash, like //data/db
.
I'd also recommend setting type=volume
in the --mount
args.
The result would look like:
docker run -d --name mongo-local -p 27017:27017 \
--mount type=volume,source=mongo-local,target=//data/db mongo