【发布时间】:2018-11-12 20:54:11
【问题描述】:
我是 Docker 的新手,并使用 Docker 设置我的第一个 Django 应用程序
我的应用程序路径看起来像
app
|- helloworld
|- __init__.py
|- manage.py
|- static_cdn
|- static_root
|- config
|- nginx
|- nginx.conf
|- Dockerfile
|- docker-compose.yml
|- requirements.txt
|- start.sh
Docerfile的内容
FROM ubuntu:18.04
# -- Install Pipenv:
FROM python:3
ENV PYTHONUNBUFFERED 1
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
# -- Install Application into container:
RUN set -ex && mkdir /app
WORKDIR /app
ADD requirements.txt /app/
RUN pip install -r requirements.txt
# -- Adding dependencies:
ADD . /app/
docker-compose.yml的内容
version: '3'
services:
nginx:
image: nginx:latest
ports:
- "9010:9010"
volumes:
- .:/app
- ./config/nginx:/etc/nginx/conf.d
- ./static_cdn:/static
depends_on:
- web
web:
build: .
command: ./start.sh
volumes:
- .:/app
- ./static_cdn:/static
ports:
- "9010:9010"
depends_on:
- db
expose:
- "9010"
db:
image: postgres
config/nginx/nginx.conf的内容
upstream web {
ip_hash;
server web:9010;
}
server {
location /static {
autoindex on;
alias /static/
}
location / {
proxy_pass http://127.0.0.1;
}
listen 9011;
server_name localhost;
}
start.sh的内容
#!/usr/bin/env bash
# Start Gunicorn processes
echo --: Starting application build
echo --: Creating migration
exec python3 manage.py makemigrations
echo ------: makemigrations complete
echo --: Running migration
exec python3 manage.py migrate
echo ------: migrate complete
echo --: Running collectstatic
exec python3 manage.py collectstatic
echo ------: collectstatic complete
echo Starting Gunicorn.
exec gunicorn helloworld.wsgi:application \
--bind 0.0.0.0:9010 \
--workers 3
现在,当我使用 docker 构建时
docker-compose up --build
它给出了错误
错误:对于 nginx 无法启动服务 nginx:驱动程序失败 在端点 koober_nginx_1 上编程外部连接 (8ea5c084a7283a16afbf136a73dc4b27d9cae35fe14d735b83199ad5d0e03431): 绑定 0.0.0.0:9010 失败:端口已分配
我已经按照一些教程来创建这些 Docker 文件和 nginx conf 文件。
1.我该如何解决上述问题。
2.以上配置需要使用FROM ubuntu:18.04吗?
编辑 2
【问题讨论】:
标签: django docker nginx docker-compose dockerfile