我正在使用docker-compose运行三个容器。其中两个取决于数据库,因此我使用wait-for-it.sh
来确保它们在数据库侦听之前不会运行。
这是my docker-compose.yml
文件:
web:
build: ./docker/web
command: ["./wait-for-it.sh", "db:5432", "--", "python", "manage.py", "runserver", "0.0.0.0:8080"]
ports:
- "8080:8080"
depends_on:
- db
- spider
links:
- db
当我运行docker-compose up
命令时收到错误消息:
web_1 | wait-for-it.sh: waiting 15 seconds for db:5432
web_1 | wait-for-it.sh: db:5432 is available after 0 seconds
web_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory
当我添加卷.:/src
时,找到了manage.py
但没有wait-for-it.sh
:
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"./wait-for-it.sh\": stat ./wait-for-it.sh: no such file or directory": unknown
我将wait-for-it.sh
文件添加到了web
服务的Dockerfile所在的目录中。
有什么主意我该如何做?
编辑 这是docker-compose中使用的Dockerfile:
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /src
COPY . /src
WORKDIR /src
RUN pip install -r requirements.txt
答案 0 :(得分:0)
我通过更改方法修复了它。向数据库服务添加了运行状况检查:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5432"]
interval: 5s
timeout: 30s
retries: 5
并重新启动对其他服务的策略:
restart: on-failure