ruby-on-rails - Docker-compose 入口点脚本使用出口 0 停止容器
问题描述
执行我的入口点脚本后,容器以 Exit 0 停止。在启动我们的网络服务器的 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
撰写文件:
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
as运行/bin/bash /app/rails-entrypoint.sh bundle exec rails server
。
当我将命令块添加到入口点脚本时,服务器已启动并正在运行,但这也不是它应该如何工作或者?
我该怎么做才能让入口点脚本和命令块正常运行?
解决方案
entrypoint.sh
当您启动容器时,将考虑启动容器的进程(在您的情况下) pid 1
,只要该进程正在运行,您的容器就会保持启动并运行,并且如果它因任何原因死亡或停止,它将停止容器并退出status0
或更高取决于主进程的实际退出状态。
您需要在入口点的末尾添加以下内容以使其与bundle exec rails server
exec "$@"
推荐阅读
- html - 打印同一页时页面显示不正确
- php - 订单号根据之前的号码自动创建
- javascript - 在单独的容器中具有丰富信息的 Highmaps
- encryption - 通过passlib.hash.pbkdf2_sha512在Node中生成PBKDF sha512 hash
- r - 如何处理变量长度不同的错误
- android - 如何使用 RxJava 从房间中获取数据
- laravel-5.8 - 使用 EmailAddress 作为列名时如何修复
- laravel - Bitbucket 管道 Laravel 与 MySQL php_network_getaddresses
- r - 使用 R 将每个字符行转换为字符串
- python - 如何在字符串中查找模式并在 HTML 代码中替换