在Windows 10上将当前目录作为Docker挂载 [英] Mount current directory as volume in Docker on Windows 10
问题描述
描述
我通过Hyper-V在Windows 10上使用docker版本1.12.5,并希望使用容器可执行文件作为命令当前路径。我建立了一个运行良好但是有一个问题来挂载当前路径的docker映像。这个想法是创建一个别名做一个docker运行--rm [...]命令,以便它可以在当前目录中的系统范围内使用。
设置
我有一个驱动器E,文件夹测试在那里有一个名为Windows主机上的文件夹的文件夹,以显示该命令正在运行。 Dockerfile创建目录/数据,将其定义为VOLUME和WORKDIR。
将E:\test作为PS中的当前目录,并使用绝对路径执行docker命令,我可以看到E:\test:
PS E:\test>码头运行--rm -it -v E:\test:/ data mirkohaaser / docker-clitools ls -la
total 0
drwxr-xr-x 2 root root 0 Jan 4 11:45。
drwxr-xr-x 2 root root 0 Jan 5 12:17 Windows主机上的文件夹
问题
我想使用当前目录,而不是绝对的符号。由于不同的错误信息,我无法使用卷中的pwd:
尝试使用($ pwd)
PS E:\test> docker运行--rm -it -v($ pwd):/ data mirkohaaser / docker-clitools ls -la
C:\Program Files\Docker\Docker\Resources\bin\docker。 exe:解析引用时出错::/ data不是有效的存储库/标记。
请参阅'C:\Program Files\Docker\Docker\Resources\bin\docker.exe运行--help'。
尝试使用/($ pwd)
< p $ p>
PS E:\test> docker运行--rm -it -v /($ pwd):/ data mirkohaaser / docker-clitools ls -la
C:\Program Files\Docker\Docker\Resources\bin\docker .exe:解析引用时出错:E:\\test不是有效的存储库/标记。
请参阅'C:\Program Files\Docker\Docker\Resources\bin\docker.exe运行--help'。
尝试使用\'pwd\'
PS E:\test> docker运行--rm -it -v'$ pwd':/ data mirkohaaser / docker-clitools ls -la
C:\Program Files\Docker\Docker\Resources\bin\docker。 exe:守护程序的错误响应:无效的绑定安装规范'E:\\test':/ data:无效模式:/ data。
请参阅'C:\Program Files\Docker\Docker\Resources\bin\docker.exe运行--help'。
尝试使用`pwd`
PS E:\test> docker运行--rm -it -v`$ pwd`:/ data mirkohaaser / docker-clitools ls -la
C:\Program Files\Docker\Docker\Resources\bin\docker。 exe:守护程序的错误响应:create $ pwd:$ pwd包含本地卷名称的无效字符,只允许[a-zA-Z0-9] [a-zA-Z0-9 _.-]。
请参阅'C:\Program Files\Docker\Docker\Resources\bin\docker.exe运行--help'。
问题
在Windows 10上的Docker中将当前目录作为卷安装的正确语法是什么?
在Windows命令行( cmd
)中,当前目录如下:
docker运行--rm -it -v%cd%:/ usr / src / project gcc:4.9
在PowerShell中,您可以使用 $ {PWD}
当前目录:
docker run --rm -it -v $ {PWD}:/ usr / src / project gcc:4.9
Description
I am using docker version 1.12.5 on Windows 10 via Hyper-V and want to use container executables as commands in the current path. I built a docker image that is running fine but have a problem to mount the current path. The idea is to create an alias do a docker run --rm [...] command so that it could be used system wide in the current directory.
Setup
I have a drive E with a folder "test" and in there a folder called "folder on windows host" to show that the command is working. The Dockerfile create the directory /data, defines it as VOLUME and WORKDIR. Having E:\test as current directory in PS and executing the docker command with an absolute path, I can see the content of E:\test:
PS E:\test> docker run --rm -it -v E:\test:/data mirkohaaser/docker-clitools ls -la
total 0
drwxr-xr-x 2 root root 0 Jan 4 11:45 .
drwxr-xr-x 2 root root 0 Jan 5 12:17 folder on windows host
Problem
I want to use the current directory and not an absolute notation. I could not use pwd in the volume because of different error messages:
Trying with ($pwd)
PS E:\test> docker run --rm -it -v ($pwd):/data mirkohaaser/docker-clitools ls -la
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error parsing reference: ":/data" is not a valid repository/tag.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
Trying with /($pwd)
PS E:\test> docker run --rm -it -v /($pwd):/data mirkohaaser/docker-clitools ls -la
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error parsing reference: "E:\\test" is not a valid repository/tag.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
Trying with \´pwd\´
PS E:\test> docker run --rm -it -v ´$pwd´:/data mirkohaaser/docker-clitools ls -la
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: Invalid bind mount spec "´E:\\test´:/data": invalid mode: /data.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
Trying with `pwd`
PS E:\test> docker run --rm -it -v `$pwd`:/data mirkohaaser/docker-clitools ls -la
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: 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.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
Question
What is the correct syntax of mounting the current directory as a volume in docker on Windows 10?
In Windows Command Line (cmd
), you can mount the current directory like so:
docker run --rm -it -v %cd%:/usr/src/project gcc:4.9
In PowerShell, you use ${PWD}
, which gives you the current directory:
docker run --rm -it -v ${PWD}:/usr/src/project gcc:4.9
这篇关于在Windows 10上将当前目录作为Docker挂载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!