在Docker容器中启动Gunicorn服务后运行shell命令

时间:2019-03-28 07:28:52

标签: python docker gunicorn

我正在使用Gunicorn运行一个简单的Python Flask应用程序。我想启动Gunicorn服务,然后在服务启动后运行自定义的shell脚本。

类似这样的东西:

FROM python:3.6.5-slim

RUN apt-get update \
  && apt-get clean \
  && apt-get install -qq -y git build-essential libpq-dev --no-install-recommends \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .

CMD ["entrypoint.sh"]

目标是在Gunicorn服务启动后运行my_custom_script.sh(当前将不运行):

#!/bin/sh

echo "Waiting for postgres..."
while ! nc -z postgres 5432; do
  sleep 0.1
done

echo "PostgreSQL started"
gunicorn -b 0.0.0.0:5000 manage:app

bash my_custom_script.sh

该脚本仅构建数据库,运行一些测试并添加一些事实数据。

0 个答案:

没有答案
相关问题