ruby-on-rails - Puma 在 docker 容器内默默退出
问题描述
Rails 5.2.3
Puma 3.12.1
我已经 dockerized 我的 rails 应用程序,当我使用命令启动容器时rails s puma
,Puma 启动然后静默退出:
=> Booting Puma
=> Rails 5.2.3 application starting in production
=> Run `rails server -h` for more startup options
之后不再有日志,容器不再运行。Puma 在 docker 之外仍然可以正常工作。
有任何想法吗?
编辑
Dockerfile
FROM ruby:2.4.5
RUN sed -i '/jessie-updates/d' /etc/apt/sources.list
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get update -qq && apt-get install -y build-essential nodejs && \
apt-get clean
RUN gem install bundler # ensure bundler 2
RUN gem cleanup
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y apt-utils yarn && \
gem install rails -v 5.2.3
ARG environment
RUN echo $environment
ENV RAILS_ENV=$environment
ENV DOCKER_IMAGE_BUILD=true
# ------------------------
# SSH Server support
# ------------------------
RUN apt-get update \
&& apt-get install -y --no-install-recommends openssh-server build-essential nodejs cron nano systemd \
&& echo "root:Docker!" | chpasswd
COPY sshd_config /etc/ssh/
RUN mkdir /myapp
WORKDIR /myapp
COPY . /myapp
RUN bundle -v
RUN bundle install
RUN yarn install
EXPOSE 3000 2222
COPY init_container.sh /myapp
RUN chmod 755 /myapp/init_container.sh
ENTRYPOINT ["/myapp/init_container.sh"]
init_container.sh:
#!/usr/bin/env bash
cat >/etc/motd <<EOL
_____
/ _ \ __________ _________ ____
/ /_\ \\___ / | \_ __ \_/ __ \
/ | \/ /| | /| | \/\ ___/
\____|__ /_____ \____/ |__| \___ >
\/ \/ \/
A P P S E R V I C E O N L I N U X
Documentation: http://aka.ms/webapp-linux
NodeJS quickstart: https://aka.ms/node-qs
EOL
cat /etc/motd
service ssh start
# whenever has to be run from the main app folder.
# it will look for schedule.rb in /myapp/config folder
cd /myapp
whenever --update-crontab
# restart cron after updating crontab
service cron restart
# for logging
crontab -l
bundle exec rails assets:precompile
yarn install
rails s puma
解决方案
不是红宝石专家,但这是我会做的,看看发生了什么。
重击容器,查看您在/myapp
目录中复制的应用程序文件是否确实存在。
docker exec -it <container name> /bin/bash
如果他们这样做,请尝试手动运行./init_container.sh
并查看会发生什么。
使用 bash,您实际上可以检查日志并找出容器仍在运行时发生的情况。
推荐阅读
- r - 使用 stringi 在 R 中生成一个唯一的随机字符串
- r - geom_point 颜色不正确
- javascript - Django动态字段 - 无法从模板中获取多个添加行的数据
- linux - 如何将变量传递到 Azure Databricks 集群初始化脚本
- windows - 用于在隔离网络上进行调试的 Microsoft 符号
- ssl - 将远程文件系统安全连接到 Kubernetes 集群
- javascript - 数组中条件的正则表达式
- php - 如何使用 Carbon 确定一个月是否已经过去
- c++ - 不存在的行包含在 Visual Studio 2017 中的动态代码覆盖率分析中
- css - CSS使外部元素固定责任