Docker - ENTRYPOINT脚本导致重新启动

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

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

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

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

  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 </ code>然后 docker-compose up </ code>时,我可以看到脚本运行,但其中有一些内容 导致容器失败并重新启动 - 然后脚本再次运行,循环继续。 docker-compose.yml有 restart:unless-stopped </ code>。</ p>

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

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

展开原文

原文

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个回答



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

定义脚本的入口点时。 它运行它,然后它结束,这意味着入口点完成。(所以脚本不执行任何错误)</ p>

所以你需要指定你的php-fpm的入口点,甚至睡眠将解决这个问题。 </ p>
</ div>

展开原文

原文

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.

dongyan5141
dongyan5141 谢谢 - 在脚本结束时添加php-fpm完成了这项工作。
一年多之前 回复
dongping4273
dongping4273 使用exec“$ @”结束ENTRYPOINT脚本,以便它作为主容器进程运行CMD是一种通常有用的模式。 如果你没有那么标准调试技巧,如docker run --rm -it imagename / bin / sh不起作用。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐