Docker + NGINX,我怎么把configuration文件从主机复制到容器?

这是我的基本NGINX设置工作!

web: image: nginx volumes: - ./nginx:/etc/nginx/conf.d .... 

我通过将./nginx复制到/etc/nginx/conf.d使用COPY ./nginx /etc/nginx/conf.d到我的容器中来replacevolumes 。 这个问题是因为,通过使用值nginx.conf引用日志文件在我的主机,而不是我的容器。 所以,我认为通过硬拷贝configuration文件到容器它将解决我的问题。

然而,在docker compose up NGINX根本没有运行。 哪里不对?

编辑:

Dockerfile

 FROM python:3-onbuild COPY ./ /app COPY ./nginx /etc/nginx/conf.d RUN chmod +x /app/start_celerybeat.sh RUN chmod +x /app/start_celeryd.sh RUN chmod +x /app/start_web.sh RUN pip install -r /app/requirements.txt RUN python /app/manage.py collectstatic --noinput RUN /app/automation/rm.sh 

泊坞窗,compose.yml

 version: "3" services: nginx: image: nginx:latest container_name: nginx_airport ports: - "8080:8080" rabbit: image: rabbitmq:latest environment: - RABBITMQ_DEFAULT_USER=admin - RABBITMQ_DEFAULT_PASS=asdasdasd ports: - "5672:5672" - "15672:15672" web: build: context: ./ dockerfile: Dockerfile command: /app/start_web.sh container_name: django_airport expose: - "8080" links: - rabbit celerybeat: build: ./ command: /app/start_celerybeat.sh depends_on: - web links: - rabbit celeryd: build: ./ command: /app/start_celeryd.sh depends_on: - web links: - rabbit 

这是您的初始设置:

 web: image: nginx volumes: - ./nginx:/etc/nginx/conf.d 

在这里,你有一个绑定卷 ,在你的容器里代理/etc/nginx/conf.d所有文件系统请求到你的主机./nginx 。 所以没有副本,只是一个绑定。 这意味着如果您更改./nginx文件夹中的文件,容器将实时查看更新的文件。

从主机加载configuration

在上次的设置中,只需在nginx服务中添加一个volume 。 你也可以在你的Web服务Dockerfile中删除COPY ./nginx /etc/nginx/conf.d行,因为它没用。

在图像中捆绑configuration

相反,如果你想把你的nginxconfiguration绑定在一个nginx图像中,你应该build立一个自定义的nginx图像。 创build一个Dockerfile.nginx文件:

 FROM nginx COPY ./nginx /etc/nginx/conf.d 

然后改变你的docker组成:

 version: "3" services: nginx: build: dockerfile: Dockerfile.nginx container_name: nginx_airport ports: - "8080:8080" # ... 

现在你的nginx容器里面会有configuration,你不需要使用卷。