您可以在运行应用程序之前创建一个执行此操作的入口点脚本。我可能会使用compose文件来部署它,而不是直接在映像中部署它,这样生产环境中就不会有动态更新的容器。
#!/bin/sh
# if a command is not provided, set a default command
if [ $# -eq 0 ]; then
set -- python app.py
fi
# update to new requirements on each container start
pip --no-cache-dir install --upgrade -r requirements.txt
# use exec to replace pid 1 with the command (e.g. python app.py)
exec "$@"
COPY entrypoint-dev.sh /
然后在开发组合文件中,可以使用该入口点:
version: '3'
services:
app:
image: app:dev
entrypoint:
- /entrypoint-dev.sh
volumes:
- .:/opt/code