docker-compose选择了错误的Ruby版本

问题描述 投票:0回答:2

运行docker-compose时,似乎选择了错误的ruby程序。使用rbenv我已经安装了2.6.2版本但是/ usr / bin下也有一个版本2.6.3。我无法删除该版本,也不能删除为sudo。我已经卸载了rbenv并重新安装了它。

奇怪的是,这:

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​​,这是错误的!

我已经尝试接受rbenv not changing ruby version下的所有建议,但没有任何帮助。有什么想法吗?

也许还有更多背景来弄清情况。我已经遵循此建议将现有的Rails应用程序泊坞化。https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development

[这里,docker-compose将创建docker。我的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

# 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

当我尝试创建所有内容时,会发生这种情况:

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
ruby docker-compose rbenv
2个回答
0
投票

https://github.com/bundler/bundler/issues/4260我想补充一点,rbenv rehash解决了此问题


0
投票

您似乎误解了Docker容器的概念。它应该是独立的,并使用其自己的环境,而不是其外部或从您的rbenv。我建议使用ruby docker image构建您的应用。从Dockerfile开始:

FROM ruby:2.6.2
...

取决于您想要的东西,如果您想减轻体重,请使用苗条或高山,...您不需要rbenv。

© www.soinside.com 2019 - 2024. All rights reserved.