我正在将rails应用程序从Heroku移动到linux服务器,并使用Caprover进行部署。这是一款非常依赖于后台作业的应用程序,我使用的是sidekiq。
我通过在Dockerfile的CMD中启动的脚本运行rails服务器(bundle exec rails server -b 0.0.0.0 -p80 &)和sidekiq (bundle exec sidekiq &),成功地使其工作。
但是,我想如果rails服务器在一个Docker容器中,并在另一个Docker容器中,则更好(关注点的分离)。但我想不出怎么把它们连接起来。我如何告诉我的rails应用程序,sidekiq住在另一个容器中?
因为我使用Caprover,所以我只能使用Dockerfile来部署我的映像,所以不能使用Dockerfiles 。
有没有办法告诉rails,它应该使用在某个Docker容器中找到的某个侧翼?如果有任何帮助的话,Caprover使用码头群。
我是不是想错了?
目前,我的设置如下:
我想要的设置是:
在我目前的限制下,这有可能吗?
我的rails + sidekiq如下所示:
FROM ruby:2.6.4-alpine
#
RUN apk update && apk add nodejs yarn postgresql-client postgresql-dev tzdata build-base ffmpeg
RUN apk add --no-cache --upgrade bash
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install --deployment --without development test
COPY . /myapp
RUN yarn
RUN bundle exec rake yarn:install
# Set production environment
ENV RAILS_ENV production
ENV RAILS_SERVE_STATIC_FILES true
# Assets, to fix missing secret key issue during building
RUN SECRET_KEY_BASE=dumb bundle exec rails assets:precompile
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 80
COPY start_rails_and_sidekiq.sh /myapp/start_rails_and_sidekiq.sh
RUN chmod +x /myapp/start_rails_and_sidekiq.sh
# Start the main process.
WORKDIR /myapp
CMD ./start_rails_and_sidekiq.shstart_rails_and_sidekiq.sh看起来如下所示:
#!/bin/bash
# Start the first process
bundle exec rails server -b 0.0.0.0 -p80 &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start Rails server: $status"
exit $status
fi
# Start the second process
bundle exec sidekiq &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start Sidekiq: $status"
exit $status
fi
# Naive check runs checks once a minute to see if either of the processes exited.
# This illustrates part of the heavy lifting you need to do if you want to run
# more than one service in a container. The container exits with an error
# if it detects that either of the processes has exited.
# Otherwise it loops forever, waking up every 60 seconds
while sleep 60; do
ps aux |grep puma |grep -q -v grep
PROCESS_1_STATUS=$?
ps aux |grep sidekiq |grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done我完全迷路了!提前感谢!
发布于 2021-02-03 03:06:29
方法1
根据CapRover文档的说法,在CapRover上运行Docker似乎是可能的,但我自己还没有尝试过。
方法2
尽管这个CapRover示例适用于不同的web应用程序,但内部访问原则是相同的:
如果您想从另一个容器中访问它,可以简单地在容器的名称中添加srv- can前缀。
但是,这种方法不是如何告诉您的Rails web应用程序在哪里找到PostgreSQL DB容器吗?或者您是通过外部子域名访问它?
https://stackoverflow.com/questions/62648308
复制相似问题