not*_*eek 5 nginx docker docker-compose
这是我可以使用的基本NGINX设置!
web:
image: nginx
volumes:
- ./nginx:/etc/nginx/conf.d
....
Run Code Online (Sandbox Code Playgroud)
我将volumes复制./nginx到/etc/nginx/conf.d使用替换COPY ./nginx /etc/nginx/conf.d到我的容器中。问题是因为通过使用值nginx.conf引用了主机中的日志文件而不是容器中的日志文件。因此,我认为通过将配置文件硬拷贝到容器中可以解决我的问题。
但是,NGINX根本没有运行docker compose up。怎么了?
编辑:
Docker文件
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
Run Code Online (Sandbox Code Playgroud)
docker-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
Run Code Online (Sandbox Code Playgroud)
这是您的初始设置有效:
web:
image: nginx
volumes:
- ./nginx:/etc/nginx/conf.d
Run Code Online (Sandbox Code Playgroud)
在这里,您有一个绑定卷,它在您的容器内代理所有文件系统请求/etc/nginx/conf.d到您的主机./nginx。所以没有副本,只有绑定。这意味着如果您更改文件./nginx夹中的文件,您的容器将实时看到更新的文件。
在您最后的设置中,只需volume在nginx服务中添加一个。您还可以删除COPY ./nginx /etc/nginx/conf.dWeb 服务 Dockerfile中的行,因为它没有用。
相反,如果您想将 nginx 配置捆绑在 nginx 映像中,则应构建自定义 nginx 映像。创建一个Dockerfile.nginx文件:
FROM nginx
COPY ./nginx /etc/nginx/conf.d
Run Code Online (Sandbox Code Playgroud)
然后更改您的 docker-compose:
version: "3"
services:
nginx:
build:
dockerfile: Dockerfile.nginx
container_name: nginx_airport
ports:
- "8080:8080"
# ...
Run Code Online (Sandbox Code Playgroud)
现在您的 nginx 容器将在其中包含配置,您不需要使用卷。
| 归档时间: |
|
| 查看次数: |
6741 次 |
| 最近记录: |