doujiao3074
doujiao3074
2019-04-26 13:58
浏览 1.1k

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).

图片转代码服务由CSDN问答提供 功能建议

我对Docker相对较新 - 我正在尝试构建一个运行Symfony 4应用程序的系统,包括 PHP-FPM,nginx和MySQL。

除了一件事,一切都有效。 当PHP-FPM容器启动时,我想运行:

 #!/ 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 
   
 
 

我创建了一个脚本 这些命令然后编辑我的DockerFile,如下所示:

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

我遇到的问题是,当我运行 docker-compose build 然后 docker-compose up 时,我可以看到脚本运行,但其中有一些内容 导致容器失败并重新启动 - 然后脚本再次运行,循环继续。 docker-compose.yml有 restart:unless-stopped

我想知道其中一个命令是否以非零代码退出, 所以试图将 exit 0 添加到脚本的末尾,但无济于事。

我做的事情愚蠢吗? 为了清楚起见,我希望这个脚本在容器的第一次启动时自动运行(如果每次启动都运行它的价值,那就没问题,而不仅仅是第一次时间)。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhong8834
    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.

    点赞 评论

相关推荐