Docker-compose 入口点脚本停止出口为 0 的容器
Docker-compose entrypoint script stops container with exit 0
执行我的入口点脚本后,容器在 0 号出口处停止。启动我们的网络服务器的组合文件中指定的命令将被忽略。
我们正在使用 docker 和 docker-compose 作为我们 rails 应用程序的环境。
入口点脚本:
#! /bin/bash
bundle exec rails assets:clobber
bundle exec rails assets:precompile
bundle exec rake db:exists && bundle exec rake db:migrate || bundle exec rake db:setup
rm -rf /aps/tmp/pids/server.pid
撰写文件:
version: '2'
services:
app:
image: registry.gitlab.com/.../.../master:latest
command: bundle exec rails server
entrypoint: /aps/rails-entrypoint.sh
volumes:
- /srv/app/log/:/app/log
- /srv/app/public/:/app/public
env_file: .env
ports:
- '0.0.0.0:3333:3000'
links:
- apppostgres
apppostgres:
image: postgres
...
volumes:
pgdata:
当我在入口点脚本为 运行 时连接到容器时,我可以看到执行的命令 运行 ps aux
为 /bin/bash /app/rails-entrypoint.sh bundle exec rails server
。
当我将我的命令块添加到入口点脚本时,服务器启动并且运行但这不是它应该如何工作或者?
我该怎么做才能获得入口点脚本和命令块运行?
当您启动容器时,启动容器的进程 - entrypoint.sh
在您的情况下 - 将被视为 pid 1
因此只要此进程是 运行 您的容器就会保留up 和 运行,如果它死掉或由于任何原因停止,它将停止容器,退出状态为 0
或更高,取决于主进程的实际退出状态。
您需要在入口点末尾添加以下内容才能使其与 bundle exec rails server
一起使用
exec "$@"
After the execution of my entrypoint script the containers stops
这几乎是定义性的:当入口点完成时容器退出。
The command specified in the compose file which is starting our webserver is ignored.
它作为命令行参数传递给入口点,由您的脚本使用它做任何适当的事情。
最常见的做法是不加修改地执行命令行参数:
#!/bin/sh
# ... do pre-launch setup ...
exec "$@"
(ENTRYPOINT
和 CMD
不会自行组合以让您 运行 在容器中按顺序排列两件事:仅入口点是运行,获取命令作为参数,容器的生命周期正好是入口点的生命周期。)
执行我的入口点脚本后,容器在 0 号出口处停止。启动我们的网络服务器的组合文件中指定的命令将被忽略。
我们正在使用 docker 和 docker-compose 作为我们 rails 应用程序的环境。
入口点脚本:
#! /bin/bash
bundle exec rails assets:clobber
bundle exec rails assets:precompile
bundle exec rake db:exists && bundle exec rake db:migrate || bundle exec rake db:setup
rm -rf /aps/tmp/pids/server.pid
撰写文件:
version: '2'
services:
app:
image: registry.gitlab.com/.../.../master:latest
command: bundle exec rails server
entrypoint: /aps/rails-entrypoint.sh
volumes:
- /srv/app/log/:/app/log
- /srv/app/public/:/app/public
env_file: .env
ports:
- '0.0.0.0:3333:3000'
links:
- apppostgres
apppostgres:
image: postgres
...
volumes:
pgdata:
当我在入口点脚本为 运行 时连接到容器时,我可以看到执行的命令 运行 ps aux
为 /bin/bash /app/rails-entrypoint.sh bundle exec rails server
。
当我将我的命令块添加到入口点脚本时,服务器启动并且运行但这不是它应该如何工作或者?
我该怎么做才能获得入口点脚本和命令块运行?
当您启动容器时,启动容器的进程 - entrypoint.sh
在您的情况下 - 将被视为 pid 1
因此只要此进程是 运行 您的容器就会保留up 和 运行,如果它死掉或由于任何原因停止,它将停止容器,退出状态为 0
或更高,取决于主进程的实际退出状态。
您需要在入口点末尾添加以下内容才能使其与 bundle exec rails server
exec "$@"
After the execution of my entrypoint script the containers stops
这几乎是定义性的:当入口点完成时容器退出。
The command specified in the compose file which is starting our webserver is ignored.
它作为命令行参数传递给入口点,由您的脚本使用它做任何适当的事情。
最常见的做法是不加修改地执行命令行参数:
#!/bin/sh
# ... do pre-launch setup ...
exec "$@"
(ENTRYPOINT
和 CMD
不会自行组合以让您 运行 在容器中按顺序排列两件事:仅入口点是运行,获取命令作为参数,容器的生命周期正好是入口点的生命周期。)