3
0

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 1 year has passed since last update.

M1 Mac の Docker で gem install grpc に失敗するときの対策

Last updated at Posted at 2022-01-27

docker-compose で bundle install したり、ビルドしようとするとエラーが発生。

色々試していたところ、grpc をインストールするステップで必ず失敗していること確認。

docker-compose run web gem install grpc

#=>
Installing grpc 1.43.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
省略
...
ERROR: 137

alpine Linuxが悪さをしている?という記事を見てビルドイメージを変更するが改善せず。

結論、docker-compose.yml で platform を明示することで動作するようになった。

以下、実行時のファイル内容を残しておきます。

# ディレクトリ構成
root/
 ├ Gemfile
 ├ Gemfile.lock
 ├ Dockerfile
 └ docker-compose.yml
# Dockerfile
FROM ruby:3.0.1

RUN apt-get update && apt-get install -y \
    build-essential \
    libpq-dev \
    nodejs \
    default-mysql-client \
    yarn

WORKDIR 'app'

COPY ./Gemfile* ./

RUN bundle install
# docker-compose.yml
version: '3.8'

services:
  ruby:
    platform: linux/x86_64 #=> 追加
    build:
      context: ./
      dockerfile: Dockerfile
    volumes:
      - ./:/app
      - ruby-bundle:/usr/local/bundle
    stdin_open: true
    tty: true
volumes:
  ruby-bundle:
# Gemfile
gem 'google-cloud-pubsub'
gem 'grpc'
gem 'google-protobuf'
gem 'pristine'
3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?