2017-02-25 31 views
1

我有一個漂亮的標準rails(5.0.1)項目,使用docker-compose(Docker version 1.12.5,build 7392c3b/docker-compose version 1.9.0,build 2585387)來管理開發環境。不幸的是,通常的開發模式,Rails在每次重新加載時重新加載類似乎都不起作用。相反,我的編碼週期已經成爲:容器需要重建並重新啓動。無法從瀏覽器重新加載

  1. ^C出docker-compose up
  2. docker-compose build
  3. docker-compose up
  4. 泡沫的,沖洗,重複

因爲我有運行多個服務,每一次我被迫退出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 

回答

-1

你會希望添加restart: always您泊塢窗撰寫文件並運行它作爲一個守護進程去docker compose up -d。這將作爲守護進程運行,不再在構建之後將其運行在前臺。如果重新啓動機器,它也會重新啓動容器。請注意,您應該在依賴項上設置restart=always以使它們在重新啓動時啓動。最後,您應該將應用程序安裝爲卷,以便您可以修改代碼並通過docker restart app對其進行循環。當你將文件拷貝到Docker容器中時,你正在創建一個快照,這就是爲什麼你每次都必須重建它。解決這個問題的方法是將你的代碼目錄安裝爲一個卷,並將編譯命令設置爲啓動CMD,以便在重新啓動時激發構建。

0

最新回答,但我發現在development.rb中設置了這個問題。

config.reload_classes_only_on_change = false

它可能有一些做https://github.com/rails/rails/issues/16678,這表明它的VirtualBox的文件時間戳和Rails reloader之間的問題。

+0

也許這也是:https://github.com/rails/rails/issues/16678#issuecomment-113058925 –

相關問題