我有一個漂亮的標準rails(5.0.1)項目,使用docker-compose(Docker version 1.12.5,build 7392c3b/docker-compose version 1.9.0,build 2585387)來管理開發環境。不幸的是,通常的開發模式,Rails在每次重新加載時重新加載類似乎都不起作用。相反,我的編碼週期已經成爲:容器需要重建並重新啓動。無法從瀏覽器重新加載
- ^C出
docker-compose up
docker-compose build
docker-compose up
- 泡沫的,沖洗,重複
因爲我有運行多個服務,每一次我被迫退出docker-compose up
,重建世界然後重新啓動,花費時間,我擔心在我的Postgres(數據庫)實例中踢太多次頭。
很明顯,安裝應用程序正在工作,因爲我可以更改視圖文件並立即查看更改。但如果我改變任何類,我不得不執行取消 - 編譯 - 重新啓動舞蹈。
泊塢窗,compose.yml
services:
app:
env_file:
- .env
depends_on:
- database
- redis
build:
context: .
args:
- environment
command: bin/rails server --port 3000 --binding 0.0.0.0
environment:
REDIS_URL: "redis://redis:6379/0"
links:
- database
- redis
network_mode: bridge
ports:
- "3000:3000"
expose:
- 3000
volumes:
- .:/app:rw
Dockerfile
# https://hub.docker.com/_/ruby/
FROM ruby:2.3-slim
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
# nodejs for JavaScript runtime
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends build-essential libpq-dev nodejs git && \
rm -rf /var/lib/apt/lists/* && \
echo "linux up-to-date"
# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
RUN mkdir /app
WORKDIR /app
# build args, provided --build-arg
ARG environment=production
ARG GIT_COMMIT=unknown
ARG VERSION=unknown
# May be overridden by docker-compose.yml
ENV RAILS_ENV=$environment RACK_ENV=$environment NODE_ENV=$environment
# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5
# Copy the main application.
COPY . ./
# Precompile Rails assets
RUN bundle exec rake assets:precompile
# Start console (starting puma creates a .pid file that we don't want)
CMD bundle exec rails console
也許這也是:https://github.com/rails/rails/issues/16678#issuecomment-113058925 –