docker-compose选择了错误的ruby版本 [英] docker-compose picks the wrong ruby version
问题描述
运行docker-compose时,似乎选择了错误的ruby程序.使用rbenv我已经安装了2.6.2版本但是/usr/bin下也有一个版本2.6.3.我无法删除该版本,也不能删除为sudo.我已经卸载了rbenv并重新安装了它.
When running docker-compose, it seems to pick the wrong ruby program. Using rbenv I have installed version 2.6.2 But there is also a version under /usr/bin that is at 2.6.3. I can't delete that version, also not as sudo. I have already uninstalled rbenv and re-installed it.
奇怪的是:
MBP-Andre:biblestudy_platform andreheijstek$ which ruby
/Users/andreheijstek/.rbenv/shims/ruby
MBP-Andre:biblestudy_platform andreheijstek$ whereis ruby
/usr/bin/ruby
当我运行docker-compose时,似乎选择了usr/bin/ruby,这是错误的选择!
When I run docker-compose, it seems to pick the usr/bin/ruby, which is the wrong one!
我已尝试接受 rbenv不会更改红宝石版本的所有建议但没有任何帮助.有什么想法吗?
I've tried to take all the advise under rbenv not changing ruby version but nothing helps. Any ideas?
也许还有更多背景来弄清情况.我已遵循此建议将现有的Rails应用程序泊坞窗化. https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development
Maybe some more background to clarify the situation. I have followed this advise to dockerise my existing rails app. https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development
在这里,docker-compose将创建docker.我的docker-compose.yml
Here, the docker-compose wil create the docker. My 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:
还有我的Dockerfile
And my 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
推荐答案
您似乎误解了docker容器的概念.它应该是独立的,并使用其自己的环境,而不是其外部的任何内容或从您的rbenv.我建议使用 ruby docker image 构建您的应用.从Dockerfile开始:
You seems to misunderstood the concept of docker container. It should be standalone and use it's own environment, not anything outside of it or from your rbenv. I would suggest to build your app with ruby docker image. Start with Dockerfile:
FROM ruby:2.6.2
...
根据您的需求,如果您想减轻体重,请使用苗条的或高山的,...您不需要rbenv.
Depend on what you want, if you want light weight, use slim or alpine,... You don't need rbenv for this.
这篇关于docker-compose选择了错误的ruby版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!