4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RubyMine / Docker for Windows: docker-compose上で作ったrbenvのRuby環境をうまくロードできないトラブル 2019-07版

Posted at

問題

  • Windows 10 Pro
  • RubyMine 2019.1
  • docker-compose (Docker for Windows)

にて、Dockerコンテナ上でrbenvを使って作ったRuby環境を、RubyMineがうまくロードしてくれない。

参考: Can't configure Remote Ruby Interpreter for docker-compose: "Unable to read RBConfig from specified interpreter" : RUBY-24360

解決方法を簡潔に

RubyMine 2019.2以降をインストールする。

ただし現状(2019-07-09)では Early Access Program (EAP) の段階なので、EAPのRubyMineを入れる。

※ 正式に2019.2以降がリリースされたときは、そちらをインストールしてください!(要ライセンス購入 or 試用)

前提

  • ホスト
    • Windows 10 Pro 10.0.18362
    • Docker for Windows Community 2.0.0.3
      • docker-composeを使用
    • RubyMine 2019.1 2019.2
      • これをバージョンアップする
  • コンテナ
    • Dockerイメージ: centos:7
      • docker-compose経由でDockerイメージを作成

Dockerfile

FROM centos:7

ENV APP_PATH /app
WORKDIR ${APP_PATH}

ENV ruby_ver="2.6.3"

ENV RBENV_ROOT="/usr/local/rbenv" 
ENV RBENV_SH="/etc/profile.d/rbenv.sh"
ENV CONFIGURE_OPTS="--disable-install-doc"
ENV PATH="${RBENV_ROOT}/bin:${PATH}"

# 日本語表示を正しくする (lessとRuby向け)
ENV LESSCHARSET="utf-8"
ENV LANG="en_US.UTF-8"

# yum (EPEL): ビルドに必要なライブラリをインストール
RUN set -x && \
    yum -y update && \
    yum -y install epel-release && \
    yum -y install \
        autoconf \
        bzip2 \
        curl \
        gcc-c++ \
        git \
        glibc-headers \
        libyaml-devel \
        make \
        openssl-devel \
        readline \
        readline-devel \
        sqlite-devel \
        zlib \
        zlib-devel \
    && \
    yum -y install less which && \
    yum clean all

# Ruby (rbenv) のインストール
RUN set -x && \
    git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv && \
    git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build && \
    echo 'eval "$(rbenv init --no-rehash -)"'  > ${RBENV_SH} && \
    source ${RBENV_SH} && \
    rbenv install ${ruby_ver} && \
    rbenv global ${ruby_ver}

# Ruby: Bundlerで必要なGemをインストール
COPY Gemfile ${APP_PATH}
COPY Gemfile.lock ${APP_PATH}
RUN set -x && \
    source /etc/profile.d/rbenv.sh && \
    rbenv exec gem install bundler && \
    bundle install

# その他、Rubyと関係ないインストールをここに書いている

VOLUME [ ${APP_PATH} ]

やったこと

  1. Early Access Program (EAP) からRubyMine 2019.2をダウンロードしインストールする
  2. Dockerfile中で which コマンドをインストールする:
    • yum -y install which
    • RubyMineがRubyのパスを検索するときにwhichを使う?
  3. RubyMineでDockerを設定する
    • ポップアップが出るので、指示に従えばOK
  4. RubyMineのSettings
    • Languages & Frameworks -> Ruby SDK and Gems
    • 「+」→「New Remote...」をクリックする→ダイアログが表示される
  5. Configure Remote Ruby Interpreter ダイアログ
    • 「Docker Compose」を選択
    • Server: 既に設定したDockerの項目を選ぶ
    • Service: docker-compose.ymlに書いたサービス名
    • Ruby or version manager path (次に説明)

Ruby or version manager path

この項目は重要です。

動いた例

/usr/local/rbenv/bin/rbenv
/usr/local/rbenv/versions/2.6.3/bin/ruby
  • フルパス
  • 2.6.3実際にインストールしたRubyのバージョン番号
  • ユーザのホームディレクトリにインストールした場合は /home/foo/.rbenv/versions/2.6.3/bin/ruby になるはずです。(試してませんが)

うまく動かなかった例

ruby
rbenv
/usr/local/rbenv/bin/rbenv
/usr/local/rbenv/shims/ruby

参考


これでOKをクリックして、Gemの一覧が出てくれば成功です!
以上です。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?