我需要用 docker 容器化一个 Django Web 项目。我将项目分为仪表板、api-server 和数据库。当我输入docker-compose up时,它打印api-server exited with code 0和 api-server 容器退出(0),然后我输入docker logs api-server,它返回空,但其他容器正常。我不知道如何检查问题。api-server目录结构如下api-server server/ Dockerfile requirements.txt start.sh ... ...一些compose yml内容如下dashboard: image: nginx:latest container_name: nginx-dashboard volumes: - /nginx/nginx/default:/etc/nginx/conf.d/default.conf:ro - /nginx/dist:/var/www/html:ro ports: - "80:80" depends_on: - api-server api-server: build: /api-server container_name: api-server volumes: - /api-server:/webapps ports: - "8000:8000" depends_on: - db db: image: postgres container_name: Postgres environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - POSTGRES_DB=postgres ports: - "5432:5432"api-server的一些Dockerfile内容如下FROM python:3.6ENV PYTHONUNBUFFERED 1RUN mkdir /webappsWORKDIR /webappsRUN apt-get clean && apt-get update && apt-get upgrade -y && apt-get install -y python3-pip libpq-dev apt-utilsCOPY ./requirements.txt /webapps/RUN pip3 install -r /webapps/requirements.txtCOPY . /webapps/CMD ["bash","-c","./start.sh"]start.sh 如下#!/usr/bin/env bashcd server/python manage.py runserver 0.0.0.0:8000输入docker-compose up结果如下root@VM:/home/test/Documents/ComposeTest# docker-compose upCreating network "composetest_default" with the default driverCreating Postgres ... doneCreating api-server ... doneCreating dashboard ... doneAttaching to Postgres, api-server, dashboardPostgres | The files belonging to this database system will be owned by user "postgres".Postgres | This user must also own the server process.......api-server exited with code 0api-server exited with code 0docker logs api-server是空的如果你们能告诉我如何检查这个问题,我将不胜感激,最好提供解决方案。
1 回答
桃花长相依
TA贡献1860条经验 获得超8个赞
您已经api-server
在构建期间复制到 Dockerfile,这应该可以正常工作,但在 Docker 组合中,它会覆盖所有 pip 包和代码。
volumes: - /api-server:/webapps
从 Docker 组合中删除该卷,它应该可以工作。
第二件事是设置 bash 脚本的权限。
COPY . /webapps/ RUN chmod +x ./start.sh
第三件事,您确实需要使用 bash 运行 python,因为 bash 中没有 CMD 无法执行的东西,那么为什么不作为 CMD 呢?
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
添加回答
举报
0/150
提交
取消