[英]How to run a Rails app in Docker on Heroku
I'm moving a legacy rails app to run in docker. 我正在移动旧版Rails应用程序以在docker中运行。 It works locally and on Virtualbox however pushing it to Heroku it fails.
它可以在本地和Virtualbox上运行,但是将其推送到Heroku失败。
If I bash into the container I can run rails c
just fine. 如果我猛扑到容器中,则可以正常运行
rails c
。 However it won't start up. 但是它不会启动。 Does anyone have any ideas?
有人有什么想法吗?
2019-04-15T15:45:36.575923+00:00 heroku[web.1]: Starting process with command `/bin/bash -c \[\"rails\",\ \"server\",\ \"-b\",\ \"0.0.0.0\",\ \"-p\",\ \44429\]`
2019-04-15T15:45:38.700762+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-15T15:45:38.616281+00:00 app[web.1]: /bin/bash: [rails,: command not found
2019-04-15T15:45:38.681262+00:00 heroku[web.1]: Process exited with status 127
Here is my Dockerfile, I was originally thinking it was getting the error because it was using /bin/sh
instead of /bin/bash
. 这是我的Dockerfile,我本来以为是因为使用
/bin/sh
而不是/bin/bash
来获取错误。 I added the line to set the SHELL
to bash but it is still getting the error. 我添加了将
SHELL
设置为bash的行,但是仍然出现错误。
FROM ruby:2.3.8
ARG RAILS_SECRET_KEY
ARG RAILS_ENV=staging
ARG GITHUB_REPO_API_TOKEN
ARG POSTGRES_USER
ARG POSTGRES_PASSWORD
ARG POSTGRES_DB
ARG DATABASE_HOST
ARG FOG_PROVIDER
ARG FOG_REGION
ARG ASSET_FOG_DIRECTORY
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
ARG DONT_INIT
ARG PORT
# change bin/sh to /bin/bash
SHELL ["/bin/bash", "-c"]
# Most of these deps are for running JS tests. You can add whatever extra deps your project has (ffmpeg, imagemagick, etc)
RUN apt-get update
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
nodejs \
qt5-default \
libqt5webkit5-dev \
xvfb \
postgresql \
postgresql-contrib \
imagemagick \
openjdk-8-jdk
# cache the gemfile seperate
COPY Gemfile* /usr/src/app/
# required at CLI
ENV BUNDLE_GITHUB__COM=${GITHUB_REPO_API_TOKEN}:x-oauth-basic
# You'll need something here. For development, you don't need anything super secret.
ENV SECRET_KEY_BASE=${RAILS_SECRET_KEY}
# this tells container to cd into app directory
WORKDIR /usr/src/app
# so we don't have to reinstall all the gems when we add just one when we build a new container
ENV BUNDLE_PATH /gems
RUN bundle install
# copy app dir into /usr/src/app in container
COPY . /usr/src/app/
RUN DB_ADAPTER=nulldb bundle exec rake assets:precompile
# for the irritating times the server doesn't clean up when container shutsdown
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", $PORT]
#!/bin/bash
set -e
if [ -f tmp/pids/server.pid ]; then
rm tmp/pids/server.pid
fi
exec "$@"
You may need to run your CMD command in shell form like 您可能需要以shell形式运行CMD命令,例如
CMD bundle exec rails server -b 0.0.0.0 -p $PORT
Because it's going to be run as /bin/bash -c {CMD}
, but /bin/bash -c ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", $PORT]
is not a valid command. 因为它将作为
/bin/bash -c {CMD}
,但是/bin/bash -c ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", $PORT]
是无效命令。
Also you may want (not required in this specific case) to set BUNDLE_BIN
env variable along with BUNDLE_PATH
另外,您可能希望(在此特定情况下不需要)设置
BUNDLE_BIN
env变量以及BUNDLE_PATH
ENV BUNDLE_PATH=/gems \
BUNDLE_BIN=/gems/bin \
GEM_HOME=/gems
ENV PATH="${BUNDLE_BIN}:${PATH}"
It will allow command without bundle exec
to work correctly too 它将允许没有
bundle exec
命令也正常工作
CMD rails server -b 0.0.0.0 -p $PORT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.