前提・実現したいこと
Dockerを使ってReactとRails APIでWebアプリを作りたい。
発生している問題・エラーメッセージ
$ docker-compose run api rails new . --api --database=postgresql $ docker-compose run --rm front sh -c "npm install -g create-react-app && create-react-app reactapp" $ docker-compose up
これらを順番に実行していると下のようなエラーが起きます。
api_1 | Bundler::GemNotFound: Could not find msgpack-1.4.5 in any of the sources api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:91:in `block in materialize' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:85:in `map!' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/spec_set.rb:85:in `materialize' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:170:in `specs' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:237:in `specs_for' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/definition.rb:226:in `requested_specs' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:108:in `block in definition_method' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/runtime.rb:20:in `setup' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler.rb:107:in `setup' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/bundler/setup.rb:20:in `<top (required)>' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require' api_1 | /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require' api_1 | bundler: failed to load command: rails (/usr/local/bundle/bin/rails) filesharingapp7_api_1 exited with code 1
該当のソースコード
docker_compose.yml
1version: '3.9' 2services: 3 db: 4 image: postgres 5 volumes: 6 - ./docker/db/data:/var/lib/postgresql/data 7 environment: 8 POSTGRES_PASSWORD: password 9 api: 10 image: ikko3dayo/api 11 command: sh -c "rm -f /api/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 12 volumes: 13 - ./api:/api 14 - ./api/vendor/bundle:/api/vendor/bundle 15 ports: 16 - '3000:3000' 17 depends_on: 18 - db 19 front: 20 image: ikko3dayo/front 21 volumes: 22 - ./front:/usr/src/app 23 command: sh -c "cd reactapp && yarn start" 24 ports: 25 - '8000:3000' 26volumes: 27 postgresql_db: 28 driver: local 29
ikko3dayo/apiのイメージは下のファイルから構成してます。
Dockerfile
1# syntax=docker/dockerfile:1 2FROM ruby:2.5 3RUN apt-get update -qq && apt-get install -y nodejs postgresql-client 4 5WORKDIR /api 6COPY Gemfile /api/Gemfile 7COPY Gemfile.lock /api/Gemfile.lock 8RUN bundle install 9 10# Add a script to be executed every time the container starts. 11COPY entrypoint.sh /usr/bin/ 12RUN chmod +x /usr/bin/entrypoint.sh 13ENTRYPOINT ["entrypoint.sh"] 14EXPOSE 3000 15 16# Configure the main process to run when running the image 17CMD ["rails", "server", "-b", "0.0.0.0"]
Gemfile
1source 'https://rubygems.org' 2gem 'rails', '~> 5.2.6'
entrypoint.sh
1#!/bin/bash 2set -e 3 4# Remove a potentially pre-existing server.pid for Rails. 5rm -f /api/tmp/pids/server.pid 6 7# Then exec the container's main process (what's set as CMD in the Dockerfile). 8exec "$@"
また、ikko3dayo/frontは以下のファイルで構成しています。
Dockerfile
1FROM node:17.5-alpine 2WORKDIR /usr/src/app
これらのイメージを下のコマンドを実行してマルチCPUアーキテクチャサポートを利用してdockerHubにpushしています。
$ docker buildx build --platform linux/amd64,linux/arm64 -t ikko3dayo/app_name:latest --push .
試したこと
dockerHubにpushせずにそのままbuildすれば普通に動きます。
補足情報(FW/ツールのバージョンなど)
実行環境はM1チップのMacとCentOS 7で、どちらの環境でも同じエラーが起こります。
Docker 関係のVersionは以下のとおりです。
docker-compose version 1.29.2, build 5becea4c Docker version 20.10.8, build 3967b7d
環境の構築につまずき3日も学習が進んでいません。
どなたか助けてください(T_T)。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。