我使用Docker Compose构建一个多容器Docker Django应用程序。我有一个docker-compose.yml文件,它设置了4个容器:web,nginx,postgres和redis。当我执行docker-compose构建时,它可以正常工作并为我的图像提供一个键,但是当我尝试运行它时,我收到此错误
nginx: [emerg] host not found in upstream "web" in /etc/nginx/sites-enabled/django_project:12
我是Docker的新手,并且使用yml进行配置,所以我不确定问题所在。
搬运工-compose.yml
version: '3'
services:
web:
restart: always
build: .
expose:
- "8005"
links:
- postgres:postgres
- redis:redis
volumes:
- /usr/src/app
- /usr/src/app/static
env_file: .env
command: /usr/local/bin/gunicorn docker_app.wsgi:application -w 2 -b :8005
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
volumes:
- /www/static
links:
- web:web
postgres:
restart: always
image: postgres:latest
ports:
- "5432:5432"
volumes:
- ./pgdata:/var/lib/postgresql/data/
redis:
restart: always
image: redis:latest
ports:
- "6379:6379"
volumes:
- ./redisdata:/data
- ./redisdata:/data:rw
项目树
├── Dockerfile
├── Makefile
├── Procfile
├── README.md
├── celerybeat-schedule
├── circle.yml
├── devops
├── docker-compose.yml
├── jwtAuth.py
├── manage.py
├── newrelic.ini
├── nginx
│ ├── Dockerfile
│ └── sites-enabled
│ └── django_project
├── requirements.txt
├── start.sh
└── docker_app
├── __init__.py
├── admin.py
├── api
├── celery.py
├── clients
├── content
├── custom_storages.py
├── factories.py
├── ingest
├── media_library
├── page_modules
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── fixtures
│ ├── models.py
│ ├── tasks.py
│ ├── tests.py
│ ├── utils.py
│ └── views.py
├── paginators.py
├── products
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── reporting
│ └── __pycache__
│ ├── __init__.py
│ ├── base.pyc
│ ├── circle.py
│ ├── prod.py
│ └── settings_local.py
├── urls.py
├── utils
│ ├── __init__.py
│ ├── __pycache__
│ ├── tools.py
└── wsgi.py
Dockerfile
FROM python:3-onbuild
的nginx / Dockerfile
FROM tutum/nginx
RUN rm /etc/nginx/sites-enabled/default
ADD sites-enabled/ /etc/nginx/sites-enabled
的nginx / / django_project启用位点-
server {
listen 80;
server_name example.org;
charset utf-8;
location /static {
alias /usr/src/app/static;
}
location / {
proxy_pass http://web:8005;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}