Forum Discussion
Problem with bind volumes in Docker CLI
Hi,
When I create a Docker container with a bind volume using PowerShell 7.4.1, for example, this action:
docker run --rm -d -p 80:80 --mount type=bind,target=/usr/share/nginx/html,source=${pwd}\docs nginx
the command doesn't work and shows the next message:
docker: Error response from daemon: ${pwd}\docs%!(EXTRA string=is not a valid Windows path).
But if I try the same command with PowerShell 5.1,
- LainRobertsonSilver Contributor
Hi, Carlos.
That makes sense given "pwd" returns an object and not a string.
You likely want to leverage the Path property of the returned object that pwd provides.
Cheers,
Lain
- LainRobertsonSilver Contributor
I also have to wonder - though I'm not familiar with the docker command or its errors - if it's not simply saying that you cannot have the trailing " nginx" preceded by a space, and perhaps need surrounding quotes? (Assuming it's intended to be part of the source path.)
What happens if you run this instead?
docker run --rm -d -p 80:80 --mount type=bind,target=/usr/share/nginx/html,source="$((pwd).Path)\docs nginx"
Cheers,
Lain