无法将 nginx.conf 卷映射到容器中的目录

问题描述 投票:0回答:1

首先,我只在我的 Linux VPS 上遇到这个问题。我的 Windows 开发机器上不存在此问题。

我的 VPS 运行的是 Ubuntu 23.04

问题

当我尝试从 docker-compose 脚本启动 docker 容器时,Nginx 容器出现错误并吐出以下内容:

root@srv502529:/docker_projects/personal-site-2024# docker-compose up
Creating network "personal-site-2024_default" with the default driver
Creating personal-site-2024_api_proxy_server_1 ... done
Creating personal-site-2024_webserver_1        ... done
Creating personal-site-2024_cms_server_1       ... done
Creating personal-site-2024_nginx_1            ... error

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 "/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5000: 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 "/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5000: 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

我认为造成这种情况的常见原因是 nginx.conf 不在指定的位置,但就我而言,它绝对是: screenshot of my project directory

docker-compose 的片段

services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - /nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - webserver
      - api_proxy_server
      - cms_server

我尝试过的事情

我尝试过使用此体积映射

./nginx:/etc/
。它显然已加载,并且我在控制台中收到一条
done
消息,但随后我收到此错误:

nginx_1             | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx_1             | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx_1             | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx_1             | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
nginx_1             | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
nginx_1             | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx_1             | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx_1             | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx_1             | 2024/04/08 15:35:46 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx_1             | nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
docker ubuntu nginx nginx-config
1个回答
0
投票

您提供

/nginx.conf
作为要安装的文件的路径,但您的结构建议它应该是
./nginx.conf
/docker_projects/personal-site-2024/nginx.conf
(如果首选绝对路径)。

© www.soinside.com 2019 - 2024. All rights reserved.