[英]docker-compose picks the wrong ruby version
When running docker-compose, it seems to pick the wrong ruby program.运行 docker-compose 时,它似乎选择了错误的 ruby 程序。 Using rbenv I have installed version 2.6.2 But there is also a version under /usr/bin that is at 2.6.3.使用 rbenv 我已经安装了 2.6.2 版本,但是 /usr/bin 下还有一个版本是 2.6.3。 I can't delete that version, also not as sudo.我不能删除那个版本,也不能删除 sudo。 I have already uninstalled rbenv and re-installed it.我已经卸载了rbenv并重新安装了它。
The strange thing is this:奇怪的是:
MBP-Andre:biblestudy_platform andreheijstek$ which ruby
/Users/andreheijstek/.rbenv/shims/ruby
MBP-Andre:biblestudy_platform andreheijstek$ whereis ruby
/usr/bin/ruby
When I run docker-compose, it seems to pick the usr/bin/ruby, which is the wrong one!当我运行 docker-compose 时,它似乎选择了 usr/bin/ruby,这是错误的!
I've tried to take all the advise under rbenv not changing ruby version but nothing helps.我试图在rbenv下接受所有建议, 但没有改变 ruby 版本,但没有任何帮助。 Any ideas?有任何想法吗?
Maybe some more background to clarify the situation.也许更多的背景来澄清情况。 I have followed this advise to dockerise my existing rails app.我已按照此建议对我现有的 Rails 应用程序进行 dockerise。 https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development
Here, the docker-compose wil create the docker.在这里,docker-compose 将创建 docker。 My docker-compose.yml我的 docker-compose.yml
version: '3.4'
x-app: &app
build:
context: .
dockerfile: ./.dockerdev/Dockerfile
args:
RUBY_VERSION: '2.6.2'
PG_MAJOR: '11'
NODE_MAJOR: '11'
YARN_VERSION: '1.13.0'
BUNDLER_VERSION: '2.0.2'
environment: &env
NODE_ENV: development
RAILS_ENV: ${RAILS_ENV:-development}
image: example-dev:1.0.0
tmpfs:
- /tmp
x-backend: &backend
<<: *app
stdin_open: true
tty: true
volumes:
- .:/app:cached
- rails_cache:/app/tmp/cache
- bundle:/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
- .dockerdev/.psqlrc:/root/.psqlrc:ro
environment:
<<: *env
REDIS_URL: redis://redis:6379/
DATABASE_URL: postgres://postgres:postgres@postgres:5432
BOOTSNAP_CACHE_DIR: /bundle/bootsnap
WEBPACKER_DEV_SERVER_HOST: webpacker
WEB_CONCURRENCY: 1
HISTFILE: /app/log/.bash_history
PSQL_HISTFILE: /app/log/.psql_history
EDITOR: vi
depends_on:
- postgres
- redis
services:
runner:
<<: *backend
command: /bin/bash
ports:
- '3000:3000'
- '3002:3002'
rails:
<<: *backend
command: bundle exec rails server -b 0.0.0.0
ports:
- '3000:3000'
sidekiq:
<<: *backend
command: bundle exec sidekiq -C config/sidekiq.yml
postgres:
image: postgres:11.1
volumes:
- .dockerdev/.psqlrc:/root/.psqlrc:ro
- postgres:/var/lib/postgresql/data
- ./log:/root/log:cached
environment:
PSQL_HISTFILE: /root/log/.psql_history
ports:
- 5432
redis:
image: redis:3.2-alpine
volumes:
- redis:/data
ports:
- 6379
webpacker:
<<: *app
command: ./bin/webpack-dev-server
ports:
- '3035:3035'
volumes:
- .:/app:cached
- bundle:/bundle
- node_modules:/app/node_modules
- packs:/app/public/packs
environment:
<<: *env
WEBPACKER_DEV_SERVER_HOST: 0.0.0.0
volumes:
postgres:
redis:
bundle:
node_modules:
rails_cache:
packs:
And my Dockerfile还有我的 Dockerfile
# Taken from: https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION
RUN echo RUBY_VERSION
ARG PG_MAJOR
ARG NODE_MAJOR
ARG BUNDLER_VERSION
ARG YARN_VERSION
# Add PostgreSQL to sources list
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
# Add NodeJS to sources list
RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -
# Add Yarn to the sources list
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list
# Install dependencies
COPY .dockerdev/Aptfile /tmp/Aptfile
RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
build-essential \
postgresql-client-$PG_MAJOR \
nodejs \
yarn=$YARN_VERSION-1 \
$(cat /tmp/Aptfile | xargs) && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
truncate -s 0 /var/log/*log
# Configure bundler and PATH
ENV LANG=C.UTF-8 \
GEM_HOME=/bundle \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3
ENV BUNDLE_PATH $GEM_HOME
ENV BUNDLE_APP_CONFIG=$BUNDLE_PATH \
BUNDLE_BIN=$BUNDLE_PATH/bin
ENV PATH /app/bin:$BUNDLE_BIN:$PATH
# Upgrade RubyGems and install required Bundler version
RUN gem update --system && \
gem install bundler:$BUNDLER_VERSION
# Create a directory for the app code
RUN mkdir -p /app
WORKDIR /app
When I try to create everything, this happens:当我尝试创建所有内容时,会发生这种情况:
MBP-Andre:biblestudy_platform andreheijstek$ docker-compose up rails
biblestudy_platform_postgres_1 is up-to-date
biblestudy_platform_redis_1 is up-to-date
Starting biblestudy_platform_rails_1 ... done
Attaching to biblestudy_platform_rails_1
rails_1 | Your Ruby version is 2.6.3, but your Gemfile specified 2.6.2
biblestudy_platform_rails_1 exited with code 18
You seems to misunderstood the concept of docker container.您似乎误解了 docker 容器的概念。 It should be standalone and use it's own environment, not anything outside of it or from your rbenv.它应该是独立的并使用它自己的环境,而不是它之外的任何东西或来自你的 rbenv。 I would suggest to build your app with ruby docker image .我建议使用ruby docker image构建您的应用程序。 Start with Dockerfile:从 Dockerfile 开始:
FROM ruby:2.6.2
...
Depend on what you want, if you want light weight, use slim or alpine,... You don't need rbenv for this.取决于你想要什么,如果你想要轻量级,使用slim 或 alpine,...你不需要rbenv。
https://github.com/bundler/bundler/issues/4260我认为补充一下rbenv rehash
解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.