我想在Kubernetes中部署Django项目。现在,我正在创建一个docker映像以了解该项目。
Dockerfile
FROM python:3.7
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip3 install -r requirements.txt
docker-compose.yml
version: '3'
services:
mysql:
image: mysql:5.7
volumes:
- ./mysql:/var/lib/mysql
expose:
- "3306"
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=nlpapp
- MYSQL_USER=root
- MYSQL_PASSWORD=root
nginx:
image: nginx:alpine
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf:/etc/nginx/conf.d
- ./web/staticfiles:/django_static
ports:
- "80:80"
depends_on:
- web
redis:
image: redis:alpine
expose:
- "6379"
restart: always
web:
build: .
command: uwsgi --ini uwsgi.ini
working_dir: /code/blog
volumes:
- .:/code
expose:
- "8000"
depends_on:
- mysql
- redis
celery:
build: .
command: celery -A blog worker -l info
working_dir: /code/blog
volumes:
- .:/code
depends_on:
- mysql
- redis
uwsgi.ini
[uwsgi]
socket=:8000
chdir=/code/blog
module=blog.wsgi:application
pidfile=/tmp/blog-master.pid
master=True
vacuum=True
processes=1
max-requests=5000
这些是主要文件。当我要在那时候启动docker-compose up命令时,MySQL,Redis,nginx,celery容器运行正常,但WSGI(web)容器未运行并显示错误。
错误:针对Web无法启动服务Web:OCI运行时创建失败:container_linux.go:345:启动容器进程导致“ exec:\“ uwsgi \”:在$ PATH中找不到可执行文件:未知
错误:启动项目时遇到错误
将命令更改为:
command: /usr/local/bin/uwsgi --ini uwsgi.ini
并确保uwsgi.ini
中有/code/blog