这是我的基本NGINX设置有效!
web:
image: nginx
volumes:
- ./nginx:/etc/nginx/conf.d
....
我使用volumes
将./nginx
复制到/etc/nginx/conf.d
,将COPY ./nginx /etc/nginx/conf.d
替换为我的容器。问题是因为,通过使用值,nginx.conf引用我的主机中的日志文件而不是我的容器。所以,我认为通过将配置文件硬编码到容器中它将解决我的问题。
然而,NGINX根本没有在docker compose up
运行。有什么问题?
编辑:
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
答案 0 :(得分:2)
这是您的初始设置:
web:
image: nginx
volumes:
- ./nginx:/etc/nginx/conf.d
您的容器内有一个bind volume个代理,/etc/nginx/conf.d
位于您的主机./nginx
的所有文件系统请求。所以没有副本,只是一个绑定。
这意味着如果您更改./nginx
文件夹中的文件,您的容器将实时查看更新的文件。
在上次设置中,只需在volume
服务中添加nginx
即可。
您还可以删除Web服务Dockerfile中的COPY ./nginx /etc/nginx/conf.d
行,因为它没用。
相反,如果你想在nginx图像中捆绑你的nginx配置,你应该构建一个自定义的nginx图像。创建Dockerfile.nginx
文件:
FROM nginx
COPY ./nginx /etc/nginx/conf.d
然后更改你的docker-compose:
version: "3"
services:
nginx:
build:
dockerfile: Dockerfile.nginx
container_name: nginx_airport
ports:
- "8080:8080"
# ...
现在你的nginx容器里面有配置,你不需要使用卷。