Docker volume mapping folder issue on Windows 10 - docker

I am trying to run the following command
docker run -p 3000:3000 -v/app/node_modules -v $(pwd):/app 2ef0206fcf99
I am getting the following error
docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
How can I fix the issue?

1) Using Windows Powershell, following works for me:
docker run --rm -it -v ${pwd}:/mydir nginx:latest bash
Note:
I have used curly braces around pwd instead of small braces
2) Using Git Bash, following syntax should work:
winpty docker run --rm -it -v "/$PWD":/mydir nginx:latest bash
Note:
If you do not use winpty at the start of the command, you will get error message: the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
Also notice the / before $PWD. Without the /, it will not throw error but i noticed that it didn't mount the directory.

I also had the same issue on windows make sure that you put "$PWD" something like this so your command should be something like this
docker run --rm -it -p 3000:3000 -v "$PWD:/app" 2ef0206fcf99
or another way is
docker run --rm -it -p 3000:3000 --volume="$PWD:/app" 2ef0206fcf99

Related

Docker: error while creating mount source path. How can i fix it?

Tks all, idk why, but now its working
I learn to use docker. I try mount a host directory in a Docker container: >docker run -it -v /Users/Kell/Desktop/data:/home/data 77
And this is error: docker: Error response from daemon: error while creating mount source path '/Users/Kell/Desktop/data': mkdir /Users: file exists.
**I use windows and docker 20.10.12, 77 is imageID **
I tried in another disk and tried many ways but still not working. Can u help me ?
If you learning docker from scratch it is recommended to use --mount and not -v anymore: Mount > v
The syntax of --mount and -v differs, so here you' find both: How to mount
Path style in Windows depends on the console you are using. Some are just working in one and not in another.
Windows-Style: docker run --rm -ti -v C:\Users\user\work:/work alpine
Pseudo-Linux-Style in Windows: docker run --rm -ti -v /c/Users/user/work:/work alpine as well as //c/
Inside WSL: docker run --rm -ti -v /mnt/c/Users/user/work:/work alpine
See: Path conversion in Windows

Using Docker in interactive mode using an official Microsoft .Net Core SDK image

I'm trying to enter interactive mode using an official Microsoft .Net Core image and use typical .Net commands such as 'dotnet build', but all I get is an '>' cursor. What am I doing wrong?
I'm using the following command:
docker run -it -v $(pwd):/app' -w '/app' -p 8000:80 mcr.microsoft.com/dotnet/core/sdk /bin/bash
I was hoping to get a root command prompt, but all I'm getting is '>'
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
Options:
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a
container
-e, --env list Set environment variables
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format:
<name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
After running your container, run command docker ps to take [Container ID]
And after you are able to run the command like there docker exec -it [Container ID] bash .
You are misssing the initial quote here:
-v $(pwd):/app'
That should be:
-v "$(pwd):/app"
It needs to be a double-quote for $(pwd) to be evaluated correctly by the shell. Otherwise the shell will send the literal $(pwd) which is not a valid path.
It seems no one gives a direct answer, this one works for me:
docker run --rm -it -v $PWD:/app -w /app -p 8000:80 mcr.microsoft.com/dotnet/core/sdk /bin/bash

Error response from daemon: Mount denied - Error got while running docker application, which was working last night

Suddenly my docker run stopped working last night, which was working before. docker build is working fine, but I get the below error when trying to run the container.
Command
docker run -it --rm -p 9001:4200 -v ${pwd}/src:/app/src angularclient
Error message
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error
response from daemon: Mount denied: The source path
"E:/Karthik/angular/src" doesn't exist and is not known to Docker. See
'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
I tried running the following command in the power shell:
refreshenv
set MSYS_NO_PATHCONV=1
set COMPOSE_CONVERT_WINDOWS_PATHS=1
try this:
docker run -it --rm -p 9001:4200 -v E:/Karthik/angular/src:/app/src angularclient
It seems that you can't use ${pwd} and ./ on win cmd and Git Bash. You can only use absolute paths.
Add this on your ~/.bash_profile:
export MSYS_NO_PATHCONV=1
Add / to prefix of path as below.
docker run -it --rm -p 9001:4200 -v /${pwd}/src:/app/src angularclient
Ensure the drive is shared in Docker settings "Shared Drives".
Create the full path if it doesn't already exist.
Add trailing / to the path.

Volume path or Mount in Windows container

Description
I got error "Error response from daemon: invalid mount config for type "volume": invalid mount path" in Windows Container
Steps to reproduce the issue:
1. DockerFile
FROM microsoft/aspnetcore-build AS base
WORKDIR /app
ENTRYPOINT [ "dotnet", "Test.dll" ]
Run command docker build -t docker-vol .
Run Command docker run -it -p 8001:80 -v D:\Projects\Docker\publish:c:/app --name docker-vol-test docker-vol (This works)
Run Command docker run -it -p 8001:80 --mount "source=D:\Projects\Docker\publish,target=c:/app" --name docker-vol-test docker-vol This fails with Error response from daemon: invalid mount config for type "volume": invalid volume name
I am wondering how to work with --mount and whether it is possible to use relative path instead of absolute path with -v?
You are using a bind mount, but because you have not specified a type, then it has defaulted to volume. In this case, source must be the name of the volume, or omitted for an anonymous volume.
Because you have give a path instead, you are getting this error. If you add a type key to your command, it should work:
docker run -it -p 8001:80 --mount 'type=bind, source="D:\Projects\Docker\publish", target="c:/app"' --name docker-vol-test docker-vol
In answer to your second point, bind mounts require an absolute path. The usual way to use a relative path in Linux-land is to prepend the path with $PWD. In Windows, the equivalent of SPWD would be %cd%, so if you were running from D:\Projects\Docker, then the above would probably be:
docker run -it -p 8001:80 --mount 'type=bind, source="%cwd%\publish", target="c:/app"' --name docker-vol-test docker-vol
Note that I have no experience of Docker under Windows, but I believe the above should work.
The above is correct but if you want to use -v instead the syntax is: docker run -v C:\SomePath:C:\app\somePath image
Note the path must exist or the command fails.

Docker: How to mount current directory in Windows 10

I am using docker toolbox v17.03 in Windows 10 Home. I am playing with flask app from python slim. I tried to mount the current directory to app and tried ${PWD} and %cd% like below.
docker container run -it -p 5000:5000 -e FLASK_APP=app.py --rm -e FLASK_DEBUG=1 -v %cd%:/app web1
==> Got the error saying invalid characters
docker container run -it -p 5000:5000 -e FLASK_APP=app.py --rm -e FLASK_DEBUG=1 -v ${PWD}:/app web1
==> Neither error nor working
The second form ${PWD} would be working in a Powershell session.
If it still says "invalid characters", that means:
the %cd% is not resolved as an absolute path
it includes characters that are not in [a-zA-Z0-9][a-zA-Z0-9_.-], making it inelligible for a volume name.
Double-check what %cd% returns, and if there is any special non-ascii character in it (or spaces)

Resources