pro*_*typ 1 ruby-on-rails docker docker-compose docker-entrypoint
执行入口点脚本后,容器以 Exit 0 停止。启动 Web 服务器的 compose 文件中指定的命令将被忽略。
我们使用 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
Run Code Online (Sandbox Code Playgroud)
撰写文件:
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:
Run Code Online (Sandbox Code Playgroud)
当我在入口点脚本运行时连接到容器时,我可以看到执行的命令以ps aux
as运行/bin/bash /app/rails-entrypoint.sh bundle exec rails server
。
当我将命令块添加到入口点脚本时,服务器已启动并运行,但这不是它应该如何工作的,或者?
我该怎么做才能让入口点脚本和命令块正常运行?
entrypoint.sh
当您启动容器时,将考虑启动容器的进程(在您的情况下) pid 1
,因此只要该进程正在运行,您的容器就会保持正常运行,如果它因任何原因死亡或停止,它将停止容器并退出status0
或更高取决于主进程的实际退出状态。
您需要在入口点末尾添加以下内容才能使其与bundle exec rails server
exec "$@"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3569 次 |
最近记录: |