2017-03-22 40 views
0

更新:我已將[或a?]問題縮小到我的services: app: volumes字典中的- groupy-gemcache:/usr/local/bundle行。如果我刪除它,容器運行正常[我認爲],但大概我失去了我當地的寶石緩存。docker +中的Bundler鎖定無法安裝寶石(Solved-docker CMD vs ENTRYPOINT)

tldr:運行搬運工,撰寫構建之後,事情似乎好,但我不能運行任何gembundle在我的運行搬運工容器,如果我補充一下我的Gemfile。例如,後docker-compose build && docker-compose run app bash

[email protected]:/src# bundle check 
The Gemfile's dependencies are satisfied 
[email protected]:/src# echo 'gem "hello-world"' >> Gemfile 
[email protected]:/src# bundle 
Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile. 
Run `bundle install` to install missing gems. 
[email protected]:/src# bundle install 
Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile. 
Run `bundle install` to install missing gems. 
[email protected]:/src# gem 
Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile. 
Run `bundle install` to install missing gems. 
[email protected]:/src# gem env 
Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile. 
Run `bundle install` to install missing gems. 

我還是蠻新手與碼頭工人,但我一直在嘗試配置,可以構建一個完美的dockerfile,緩存寶石和更新,同時還承諾其Gemfile.lock的與git [也許這實際上並不完美,我願意接受建議]。在我的使用案例中,我使用了一個docker撰寫文件,其中包含rails應用程序和sidekiq工作人員的圖像以及postgres和redis圖像 - 非常類似於描述herehere的設置。

我Dockerfile [有些事情註釋掉了,我從上面的教程鵝卵石:

FROM ruby:2.3 
    ENTRYPOINT ["bundle", "exec"] 
    ARG bundle_path 
    # throw errors if Gemfile has been modified since Gemfile.lock 
    # RUN bundle config --global frozen 1 
    ENV INSTALL_PATH /src 
    RUN mkdir -p $INSTALL_PATH 
    WORKDIR $INSTALL_PATH 



    # Install dependencies: 
    # - build-essential: To ensure certain gems can be compiled 
    # - nodejs: Compile assets 
    # - npm: Install node modules 
    # - libpq-dev: Communicate with postgres through the postgres gem 
    # - postgresql-client-9.4: In case you want to talk directly to postgres 
    RUN apt-get update && apt-get install -qq -y build-essential nodejs npm libpq-dev postgresql-client-9.4 --fix-missing --no-install-recommends && \ 
    rm -rf /var/lib/apt/lists/* 

    COPY app/Gemfile app/Gemfile.lock ./ 

    # Bundle and then save the updated Gemfile.lock in our volume since it will be clobbered in the next step 
    RUN echo $bundle_path && bundle install --path=$bundle_path && \ 
    cp Gemfile.lock $bundle_path 

    # ./app contains the rails app on host 
    COPY app . 

    # Unclobber the updated gemfile.lock 
    RUN mv $bundle_path/Gemfile.lock ./ 

    CMD ["./script/start.sh"] 

泊塢窗,compose.yml:

version: '2' 
volumes: 
    groupy-redis: 
    groupy-postgres: 
    groupy-gemcache: 

services: 
    app: 
    build: 
     args: 
     bundle_path: /usr/local/bundle 
     context: . 
     dockerfile: Dockerfile 
    command: "./script/start.sh" 
    links: 
     - postgres 
     - redis 
    volumes: 
     - ./app:/src 
     - groupy-gemcache:/usr/local/bundle 
    ports: 
     - '3000:3000' 
    env_file: 
     - .docker.env 
    stdin_open: true 
    tty: true 

回答

0

哇,我想通了。問題來自我的ENTRYPOINT dockerfile命令,如this article on CMD vs ENTRYPOINT末尾解釋的那樣。

我相信ENTRYPOINT ["bundle", "exec"]CMD ["./script/start.sh"]docker-compose run app bash的結果是運行一個命令,如bundle exec 'bash'。我通過從dockerfile中刪除入口點來確認這一點,如上所述輸入shell並手動運行bundle exec 'bash',果然我登錄了一個子shell,在那裏我無法運行任何bundle或gem命令 - 必須兩次離開exit