问题
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.
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!
I've tried to take all the advise under rbenv not changing ruby version but nothing helps. Any ideas?
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
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:
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
回答1:
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
...
Depend on what you want, if you want light weight, use slim or alpine,... You don't need rbenv for this.
回答2:
https://github.com/bundler/bundler/issues/4260
I thinks add that an rbenv rehash
solved this issue
来源:https://stackoverflow.com/questions/59281193/docker-compose-picks-the-wrong-ruby-version