は、私は別の容器(postgresのサーバ)の設定を完了するまで待つ必要があるPythonのドッキングウィンドウコンテナを持っています。私は標準のwait-for-it.shを試しましたが、いくつかのコマンドは含まれていませんでした。私は基本的な睡眠を試みましたが(shファイルで)、今は私が待っているコマンドを最終的に実行しようとしたときにexec: 300: not found
を報告しています。私はまた、単にPythonスクリプトを実行することができますが、理想的に私が使用したいのですが知っているどのように私は(好ましくは画像を変更、または画像を拡張することなく。)これを回避んpythonでwait-for-it.sh実行ドッカーコンテナ
WAIT- for -it.shは、サーバがスリープするのではなく、サーバが立ち上がるのを待つ。
Dockerfile(スタッファー用):
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
ドッキングウィンドウ-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="[email protected]"
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
は、あなたは私のDockerfileとエントリポイントを示していただけますか? –
必要に応じてbashコマンドをインストールする最も良い方法は何ですか?私は理論的にpsqlを持つためにpythonイメージにpostgresをインストールすることができますが、execは私がインストールすべきものではありません。 –
は、ライン 'コマンドを変更しよう:[ "300"、 "localhostを:5432"、 "-t" "./wait-for-postgres.sh"、 " - "「、 "パイソン" は./stuffing。 PY " "--file"、" ./afile "]' 'コマンドに:[" ./wait-for-postgres.sh " "ローカルホスト:5432"、 "-t"、 "300"、" - - 「 『パイソン』、」./stuffing.py「 『--file』、」./afile "]、それは最初の引数は、ホスト名になることを期待するために' 待ち:ポート –