首页 > 解决方案 > 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

标签: ruby-on-railsdockerpuma

解决方案


不是红宝石专家,但这是我会做的,看看发生了什么。

重击容器,查看您在/myapp目录中复制的应用程序文件是否确实存在。

docker exec -it <container name> /bin/bash

如果他们这样做,请尝试手动运行./init_container.sh并查看会发生什么。

使用 bash,您实际上可以检查日志并找出容器仍在运行时发生的情况。


推荐阅读