我有一个 Python Docker 容器,需要等到另一个容器(Postgres 服务器)完成设置。我尝试了标准的 wait-for-it.sh,但其中几个命令未被包含。我尝试了基本的 sleep(同样在 sh 文件中),但现在当尝试最终执行我正在等待的命令时,它报告“exec: 300: not found”。
如何解决这个问题(最好不要更改镜像,也不需要扩展镜像)?
我知道我也可以运行一个 Python 脚本,但理想情况下,我想使用 wait-for-it.sh 等待服务器启动,而不仅仅是睡眠。
Dockerfile(用于 stuffer):
如何解决这个问题(最好不要更改镜像,也不需要扩展镜像)?
我知道我也可以运行一个 Python 脚本,但理想情况下,我想使用 wait-for-it.sh 等待服务器启动,而不仅仅是睡眠。
Dockerfile(用于 stuffer):
FROM python:2.7.13
ADD ./stuff/bin /usr/local/bin/
ADD ./stuff /usr/local/stuff
WORKDIR /usr/local/bin
COPY requirements.txt /opt/updater/requirements.txt
COPY internal_requirements.txt /opt/stuff/internal_requirements.txt
RUN pip install -r /opt/stuff/requirements.txt
RUN pip install -r /opt/stuff/other_requirements.txt
docker-compose.yml:
version: '3'
services:
local_db:
build: ./local_db
ports:
- "localhost:5432:5432"
stuffer:
build: ./
depends_on:
- local_db
command: ["./wait-for-postgres.sh", "-t", "300", "localhost:5432", "--", "python", "./stuffing.py", "--file", "./afile"]
我想要使用的脚本(但无法使用,因为没有psql或exec):
#!/bin/bash
# wait-for-postgres.sh
set -e
host="$1"
shift
cmd="$@"
until psql -h "$host" -U "postgres" -c '\l'; do >&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $cmd
command: ["./wait-for-postgres.sh", "-t", "300", "localhost:5432", "--", "python", "./stuffing.py", "--file", "./afile"]
到command: ["./wait-for-postgres.sh", "localhost:5432", "-t", "300", "--", "python", "./stuffing.py", "--file", "./afile"]
wait for it期望第一个参数为主机名:端口。 - Bukharov Sergey