无法将带有空格的主机目录映射到容器目录(绑定安装) - Docker 快速入门终端(Bash),Windows 10 [英] Cannot map a host directory with spaces to a container directory (bind mounts) - Docker Quickstart Terminal (Bash), windows 10
问题描述
我是 Docker 的新手.我正在学习使用绑定安装和卷的教程,我使用的是 Windows 10 Docker 快速入门终端 (bash) 和 Docker 19.03.1.
I am a newbie with Docker. I am following a tutorial in which I am using bind mounts and volumes, I am using windows 10 Docker quickstart terminal (bash) and Docker 19.03.1.
我在目录.../dockerfile-sample-2
(注意:此路径包含空格)包含:
I am in the directory .../dockerfile-sample-2
(Note: this path contains spaces) containing:
$ ls -al
total 18
drwxr-xr-x 1 Tommaso 197121 0 mag 10 11:55 ./
drwxr-xr-x 1 Tommaso 197121 0 mag 1 19:20 ../
-rw-r--r-- 1 Tommaso 197121 410 apr 11 09:06 Dockerfile
-rw-r--r-- 1 Tommaso 197121 249 apr 11 09:06 index.html
-rw-r--r-- 1 Tommaso 197121 0 mag 10 11:55 testme.txt
现在我运行并得到以下结果:
Now I run and get the followings:
.../dockerfile-sample-2
$ docker container run -d --name nginx -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
b8f24ee0e0b76d0b06503ce90fbd6a9e2110e40eaa4432e8c77556510c61a989
.../dockerfile-sample-2
$ docker container run -d --name nginx2 -p 8080:80 nginx
3450433e18097291936d7e62071769521eb36e92f509ad931c9e927f135df71a
现在,根据教程,通过访问 IP 地址 http://192.168.99.101/ 和 http://192.168.99.101:8080,我应该能够分别看到来自index.html 文件和原始 nginx 登陆页面.
Now, according to the tutorial, by accessing the IP addresses http://192.168.99.101/ and http://192.168.99.101:8080, I should be able to see, respectiverly, a custom landing page from the index.html file and the original nginx landing page.
然而,我只得到了两次原始的 nginx 登陆页面.
However, I only get the original nginx landing page twice.
更多,根据我的教程,通过运行
And more, according to my tutorial, by running
docker container exec -it nginx bash
cd /usr/share/nginx/html
ls –al
我应该得到上一个目录.../dockerfile-sample-2
的相同内容.
I should get the same content of the previous directory .../dockerfile-sample-2
.
然而,我只得到
root@b8f24ee0e0b7:/usr/share/nginx/html# ls -al
total 16
drwxr-xr-x 2 root root 4096 Apr 13 19:20 .
drwxr-xr-x 3 root root 4096 Apr 13 19:20 ..
-rw-r--r-- 1 root root 494 Apr 13 15:13 50x.html
-rw-r--r-- 1 root root 612 Apr 13 15:13 index.html
再一次,根据我的教程,如果我在我的 .../dockerfile-sample-2
目录中创建一个新文件,它应该出现在
and again, according to my tutorial, if I'd make a new file in my .../dockerfile-sample-2
directory, it should appear among the results of
docker container exec -it nginx bash
cd /usr/share/nginx/html
ls –al
但它没有.
我做错了什么?
这里有一些上下文:
我的正在运行的容器:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3450433e1809 nginx "/docker-entrypoint.…" 20 minutes ago Up 20 minutes 0.0.0.0:8080->80/tcp nginx2
b8f24ee0e0b7 nginx "/docker-entrypoint.…" 21 minutes ago Up 21 minutes 0.0.0.0:80->80/tcp nginx
在我的Dockerfile:
# this shows how we can extend/change an existing official image from Docker Hub
FROM nginx:latest
# highly recommend you always pin versions for anything beyond dev/learn
WORKDIR /usr/share/nginx/html
# change working directory to root of nginx webhost
# using WORKDIR is preferred to using 'RUN cd /some/path'
COPY index.html index.html
# I don't have to specify EXPOSE or CMD because they're in my FROM
在我的 Index.html 中:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Your 2nd Dockerfile worked!</title>
</head>
<body>
<h1>You just successfully ran a container with a custom file copied into the image at build time!</h1>
</body>
</html>
更新:
我敢打赌这个问题与当前工作目录包含空格有关.
I bet the problem is related to the fact that the current working directory contains spaces.
所以我删除了 nginx 容器并尝试运行其他容器.
So I removed the nginx container and tryed run other ones.
以下命令:
docker container run -d --name nginx -p 80:80 -v "$(pwd)":/usr/share/nginx/html nginx
docker container run -d --name nginx -p 80:80 -v "/d/Files Tommaso/Programmazione/Docker/udemy-docker-mastery-main/dockerfile-sample-2:/usr/share/nginx/html" nginx
docker container run -d --name nginx -p 80:80 -v "/d/Files Tommaso/Programmazione/Docker/udemy-docker-mastery-main/dockerfile-sample-2":/usr/share/nginx/html nginx
当我尝试访问 http://192.168.99.101/
时,让我的浏览器获得 403 Forbidden.
as I try to access http://192.168.99.101/
, make my browser get 403 Forbidden.
而这些其他命令:
docker container run -d --name nginx -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
docker container run -d --name nginx -p 80:80 -v /$(pwd):/usr/share/nginx/html nginx
docker container run -d --name nginx -p 80:80 -v `pwd -W`:/usr/share/nginx/html nginx
docker container run -d --name nginx -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
docker container run -d --name nginx -p 80:80 -v /d/Files Tommaso/Programmazione/Docker/udemy-docker-mastery-main/dockerfile-sample-2:/usr/share/nginx/html nginx
让我的终端响应:
C:\Applicazioni_Tommaso\Docker Toolbox\docker.exe: invalid reference format: repository name must be lowercase.
See 'C:\Applicazioni_Tommaso\Docker Toolbox\docker.exe run --help'.
我敢打赌这意味着它无法解析空格.
I bet this means it cannot parse spaces.
以及这些其他命令:
docker container run -d --name nginx -p 80:80 -v %cd%:/usr/share/nginx/html nginx
让我的终端响应:
C:\Applicazioni_Tommaso\Docker Toolbox\docker.exe: Error response from daemon: create YYYY: "YYYY" 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.
推荐答案
经过多次尝试,我可以假设
After several attempts I can assume that
- 在 Windows 10 上
- 使用 Docker 快速入门终端
Docker 19.03.1 无法管理
在-v
参数中的使用
Docker 19.03.1 cannot manage the use of <path containing spaces>
inside -v
parameter
docker container run -d --name <name> -p 80:80 -v <path containing spaces>:<destination path> <image>
我发现解决此问题的唯一方法是将源卷目录更改为文件夹中不包含空格的目录,然后运行
The only way I found to solve this problem is to change the source volume directory to a directory in which no folder contains spaces, and running
docker container run -d --name nginx -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
这篇关于无法将带有空格的主机目录映射到容器目录(绑定安装) - Docker 快速入门终端(Bash),Windows 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!