You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 23.04 VPS中Docker挂载nginx.conf文件失败问题求助

Ubuntu 23.04 VPS上Docker挂载Nginx配置文件失败

我在运行Ubuntu 23.04的Linux VPS上尝试将本地nginx.conf文件挂载到Docker容器对应路径,挂载配置./nginx.conf:/etc/nginx/nginx.conf:ro在macOS(Docker v25.0.3)和Windows 11上可正常工作,但在VPS上执行时出现如下错误:

ERROR: for personal-site-2024_nginx_1  Cannot start service nginx: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/docker_projects/personal-site-2024/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /docker_projects/personal-site-2024/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

ERROR: for nginx  Cannot start service nginx: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/docker_projects/personal-site-2024/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /docker_projects/personal-site-2024/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.

我将nginx.conf放入nginx_conf目录并使用/nginx_conf:/etc/nginx/conf.d映射时无报错,但容器内conf.d目录中不出现该文件。nginx.conf文件权限为-rwxr-xr-x 1 root root 1009 Apr 9 14:49 nginx.conf。

已尝试操作:

  • 将文件重命名为default.conf
  • 调整为目录映射

附docker-compose.yml片段:

version: '3'
services:
# This makes the dockerised containers publicly accessible so that
# runtime fetch requests made by the webserver (in browser) reach
# the containers sequestered in the docker network through forwarding
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - webserver
      - api_proxy_server
      - cms_server

内容的提问来源于stack exchange,提问作者Hayden Gorringe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 06:32:50