Docker:Nginx不';如果在docker-compose.yml中声明卷,则无法运行

Docker:Nginx不';如果在docker-compose.yml中声明卷,则无法运行,docker,nginx,docker-compose,Docker,Nginx,Docker Compose,我试图使用docker compose在docker中作为容器运行nginx,但不幸的是,我无法正确运行它 这是我的docker-compose.yml: version: '3' services: webserver: container_name: webserver hostname: webserver image: nginx ports: - 80:80 - 443:443 volumes: - ./nginx:/etc/nginx 下面是

我试图使用docker compose在docker中作为容器运行nginx,但不幸的是,我无法正确运行它

这是我的docker-compose.yml:

version: '3'
services:
 webserver:
  container_name: webserver
  hostname: webserver
  image: nginx
  ports:
   - 80:80
   - 443:443
  volumes:
   - ./nginx:/etc/nginx
下面是错误:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/01/18 19:04:26 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
我在卷中使用了相对路径和绝对路径,但它们都不起作用。如果我在主机上有可用的目录,它将无法工作。如果我在主机中没有目录,当我运行docker compose up时,它将在主机中为nginx创建一个空目录,但它将保持为空

你知道我的设置有什么问题吗


谢谢。

否不要试图手动修改容器本身中的所有conf

Nginx有
/etc/Nginx/conf.d
,所以在里面安装海关会议

例如:

您当前的目录应该如下所示:

.
├── conf
│   └── custom.conf
├── docker-compose.yml
└── html
    └── index.html
docker compose.yml

服务:
nginx:
图片:nginx:latest
端口:
- 80:80
卷数:
-/conf:/etc/nginx/conf.d#这里是自定义conf
-./html:/tmp#这里有自定义html
我只是将html放在“/tmp”中,以向您显示我的自定义配置可以工作

/conf/custom.conf

server {
    listen     80;
    location / {
            root /tmp/;
            index  index.html index.htm;
    }
}
/html/index.html

nginx自定义配置
然后

$docker compose up-d
使用默认驱动程序创建网络“nginx\u default”
正在创建nginx\u nginx\u 1。。。完成
$curl本地主机
你好

否不要试图手动修改容器本身中的所有conf

Nginx有
/etc/Nginx/conf.d
,所以在里面安装海关会议

例如:

您当前的目录应该如下所示:

.
├── conf
│   └── custom.conf
├── docker-compose.yml
└── html
    └── index.html
docker compose.yml

服务:
nginx:
图片:nginx:latest
端口:
- 80:80
卷数:
-/conf:/etc/nginx/conf.d#这里是自定义conf
-./html:/tmp#这里有自定义html
我只是将html放在“/tmp”中,以向您显示我的自定义配置可以工作

/conf/custom.conf

server {
    listen     80;
    location / {
            root /tmp/;
            index  index.html index.htm;
    }
}
/html/index.html

nginx自定义配置
然后

$docker compose up-d
使用默认驱动程序创建网络“nginx\u default”
正在创建nginx\u nginx\u 1。。。完成
$curl本地主机
你好

您的主机
/nginx
文件夹的内容是什么?在交互模式下运行它,检查目录是否正确映射,以及
nginx.conf
文件是否在指定路径可用。@Spirit有一次我尝试使用空的/nginx目录,但它不起作用。然后,为了通过docker compose生成,我将其删除。这次,docker创建了它,但出现了相同的错误。它是空的如果您尝试使用空的nginx dir,它将正常失败。。您的
.nginx/
应该有一个
nginx.cong
如果没有,您将有
open()“/etc/nginx/nginx.conf”失败
@Faisal我运行了这个命令docker run-v/home/invoice app/server/nginx/:/etc/nginx/-it nginx/bin/bash,当我检查容器内的/etc/nginx时,它是空的主机
/nginx
文件夹的内容是什么?在交互模式下运行它,检查目录是否正确映射,以及
nginx.conf
文件是否在指定路径可用。@Spirit有一次我尝试使用空的/nginx目录,但它不起作用。然后,为了通过docker compose生成,我将其删除。这次,docker创建了它,但出现了相同的错误。它是空的如果您尝试使用空的nginx dir,它将正常失败。。您的
.nginx/
应该有一个
nginx.cong
如果没有,您将有
open()“/etc/nginx/nginx.conf”失败
@Faisal我运行了这个命令docker run-v/home/invoice app/server/nginx/:/etc/nginx/-it nginx/bin/bash,当我检查容器内的/etc/nginx时,它是空的