doujiao3074 2019-04-26 13:58
浏览 1740
已采纳

Docker - ENTRYPOINT脚本导致重新启动

I'm relatively new to Docker - I'm trying to build a system to run a Symfony 4 app, comprising of PHP-FPM, nginx and MySQL.

Everything works as it should except one thing. When the PHP-FPM container boots, I want to run:

#!/bin/bash
composer install
bin/console doctrine:database:create --if-not-exists
bin/console doctrine:schema:update --force
bin/console doctrine:fixtures:load --no-interaction

I created a script with these commands in and then edited my DockerFile as follows:

COPY ./docker/php/startup.sh /usr/local/bin/startup.sh
RUN ["chmod", "+x", "/usr/local/bin/startup.sh"]
ENTRYPOINT ["/usr/local/bin/startup.sh"]

The issue I'm having is that when I run docker-compose build and then docker-compose up, I can see the script runs, but something in it causes the container to fail and restart itself - the script then runs again, and the cycle continues. The docker-compose.yml has restart: unless-stopped specified by the way.

I wondered if one of the commands was exiting with a non zero code, so tried to add exit 0 to the end of the script, but to no avail.

Am I doing something daft? To be clear, I want this script to run automatically on the first boot of the container (it's fine if it runs every boot for what it's worth, not just the very first time).

  • 写回答

1条回答 默认 最新

  • dongzhong8834 2019-04-26 14:10
    关注

    https://docs.docker.com/engine/reference/builder/#entrypoint

    When you define entrypoint to your script. It runs it and after that it ends that means entrypoint is done.(so script executes no errors )

    So you need to specify your entrypoint to php-fpm or even sleep will fix this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥100 单片机hardfaulr
  • ¥20 手机截图相片分辨率降低一半
  • ¥50 求一段sql语句,遇到小难题了,可以50米解决
  • ¥15 速求,对多种商品的购买力优化问题(用遗传算法、枚举法、粒子群算法、模拟退火算法等方法求解)
  • ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)