嘗試在 docker 下運行 rails 控制臺時遇到一些問題。所有其他 rails 命令都按預期作業,但控制臺沒有。
? octopus git:(master) ? docker-compose run web bundle exec rails c
Creating octopus_web_run ... done
Could not find rake-13.0.6 in any of the sources
Run `bundle install` to install missing gems.
ERROR: 1
耙子已安裝。
? octopus git:(master) ? docker-compose run web bundle install
Creating octopus_web_run ... done
Using rake 13.0.6
Using concurrent-ruby 1.1.9
Using i18n 1.8.11
....
Bundle complete! 42 Gemfile dependencies, 144 gems now installed.
Bundled gems are installed into `./.bundle`
而且
? octopus git:(master) ? docker-compose run web bundle config list
Creating octopus_web_run ... done
Settings are listed in order of priority. The top value will be used.
app_config
Set via BUNDLE_APP_CONFIG: "/myapp/.bundle"
silence_root_warning
Set via BUNDLE_SILENCE_ROOT_WARNING: true
path
Set via BUNDLE_PATH: "/myapp/.bundle"
bin
Set via BUNDLE_BIN: "/bin"
? octopus git:(master) ? docker-compose run web bundle exec rails s -p 3000 -b '0.0.0.0'
Creating octopus_web_run ... done
=> Booting Puma
=> Rails 6.1.4.4 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.5.2 (ruby 2.7.5-p203) ("Zawgyi")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 1
* Listening on http://0.0.0.0:3000
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2022-01-17 19:28:14 0000 ===
- Goodbye!
Exiting
并且還docker-compose up照常作業。
我使用過許多類似的 docker 設定,沒有任何問題。我的想法不多了。
環境設定
- 寶石在 ./bundle 下
- 碼頭工人撰寫版本 1.29.2
- 紅寶石 2.7
- 導軌 6.1.4.4
Dockerfile
FROM ruby:2.7
RUN curl -fsSL https://deb.nodesource.com/setup_17.x | bash -
# Install yarn, for webpack
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs yarn
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
ENV GEM_HOME /myapp/.bundle
ENV BUNDLE_PATH=$GEM_HOME \
BUNDLE_APP_CONFIG=$BUNDLE_PATH \
BUNDLE_BIN=$BUNDLE_PATH/bin
ENV PATH /app/bin:$BUNDLE_BIN:$PATH
ENV NODE_OPTIONS=--openssl-legacy-provider
Docker-compose.yml
version: '3.9'
services:
db:
image: postgres:13
volumes:
- octopus-db-sync:/var/lib/postgresql/data:nocopy
environment:
POSTGRES_PASSWORD: password
redis:
image: redis
web:
build: .
command: ./start_docker_development.sh
volumes:
- octopus-sync:/myapp:nocopy
environment:
BUNDLE_APP_CONFIG: /myapp/.bundle
ports:
- "3000:3000"
depends_on:
- db
- redis
- mailcatcher
nginx:
image: nginx
volumes:
- ./nginx-develop.conf:/etc/nginx/conf.d/default.conf:z
- octopus-sync:/myapp:nocopy
ports:
- "80:80"
expose:
- "80"
depends_on:
- web
mailcatcher:
image: sj26/mailcatcher
ports:
- "1080:1080"
volumes:
octopus-sync:
external: true
octopus-db-sync:
external: true
start_docker_development.sh
#!/bin/bash
bundle check || bundle install
rm -f tmp/pids/server.pid
echo > log/development.log
echo > log/test.log
bundle exec rails s -p 3000 -b '0.0.0.0'
非常感謝任何幫助。
uj5u.com熱心網友回復:
每次執行docker-compose run時都會創建一個新容器,因此以前安裝的 gem 不再可用。
為了解決您的問題,您可以bundle install在 Dockerfile 中運行,將 gems 安裝在 app 檔案夾中,bundle install --path vendor/bundle 或者安裝默認情況下用于存盤 gems 的目錄包,通常/usr/local/bundle
uj5u.com熱心網友回復:
我發現這個問題是在 spring 4.0 ( issue 669 ) 中引入的。Bundle env 變數被忽略。
降級到spring 3.1.1解決了這個問題。
寶石檔案
gem 'spring', '~> 3.1.1'
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/414596.html
標籤:
