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

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 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试