doujiao3074 2019-04-26 05: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 06: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部