提问人:Rakesh Bakoriya 提问时间:10/6/2023 最后编辑:Rakesh Bakoriya 更新时间:10/6/2023 访问量:61
如何使用多个动态数据库在 Docker 中创建同一应用程序的多个映像?
How can I create multiple images of the same application in Docker with Multiple dynamic Database?
问:
我正在使用 rails 5.1.0
我想创建同一应用程序的多个映像, 每个图像的域和数据库会有所不同,
image_1示例
- 域 example.app.com
- 数据库 - example_production
image_2示例
- 域 example1.app.com
- 数据库 - example1_production
image_3示例
- 域 example3.app.com
- 数据库 - example3_production
#application_controller.rb
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
connects_to database: { writing: "#{request.base_url}_production", reading: "#{request.base_url}_production" }
end
语法 = docker/dockerfile:1.2
FROM ruby:2.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
# Set an environment variable where the Rails app is installed to inside of Docker image:
ENV RAILS_ROOT /var/www
RUN mkdir -p $RAILS_ROOT/app
RUN mkdir -p $RAILS_ROOT/shared
RUN mkdir -p $RAILS_ROOT/shared/tmp/sockets
RUN mkdir -p $RAILS_ROOT/shared/tmp/pids
# Set working directory, where the commands will be ran:
WORKDIR $RAILS_ROOT/app
# Setting env up
ENV RAILS_ENV='production'
ENV RACK_ENV='production'
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install --jobs 20 --retry 5
# Adding project files
COPY . .
RUN ["chmod", "+x", "./docker-entrypoint.sh"]
EXPOSE 9292
ENTRYPOINT ["./docker-entrypoint.sh"]
答: 暂无答案
评论