【发布时间】:2020-01-21 07:13:12
【问题描述】:
我想在 Docker 中运行 NGINX 并提供一些文件,但我不能这样做:
docker run --rm --name some-nginx -p 10088:80 -v mydir:/usr/share/nginx/html:ro nginx
我可以看到http://localhost:10088,但如果我尝试访问mydir/ 中的任何文件,它就会失败。例如http://localhost:10088/README.md 给出这个结果:
2020/01/21 07:10:20 [error] 6#6: *1 open() "/usr/share/nginx/html/README.md" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /README.md HTTP/1.1", host: "localhost:10088"
172.17.0.1 - - [21/Jan/2020:07:10:20 +0000] "GET /README.md HTTP/1.1" 404 153 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0" "-"
知道如何轻松设置 nginx 吗?
注意:我不想按照https://hub.docker.com/_/nginx 的建议创建新图像,我想使用音量。
注 2:我刚刚注意到(附加到 nginx 容器后):
root@a2813aa84991:/usr/share/nginx/html# ls
50x.html index.html
似乎卷mydir/ 没有安装。
【问题讨论】:
-
这能回答你的问题吗? Docker Volume not mounting any files
-
@emix 不是,但问题类似:我需要使用绝对路径而不是相对路径。
-
由于您已经使用
name:/path语法挂载了您的容器,Docker 为您创建了一个名为mydir的卷。您可以验证使用docker volume ls