
Dcokerfile
FROM ruby:2.5 RUN apt-get update -qq && apt-get install -y nodejs postgresql-client RUN mkdir /myapp WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp
docker-compose.yml
version: '3' services: db: image: postgres volumes: - ./tmp/db:/var/lib/postgresql/data web: build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/myapp ports: - "3000:3000" depends_on: - db
config/detabase.yml
default: &default adapter: postgresql encoding: unicode host: db username: postgres password: pool: 5 development: <<: *default database: myapp_development test: <<: *default database: myapp_test
エラー内容
ターミナルでdocker container lsを実行した結果
***:Rails-master ***$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1fae4ae6d4d8 rails-master_web "bash -c 'rm -f tmp/…" 4 hours ago Up 39 minutes 0.0.0.0:3000->3000/tcp rails-master_web_1
#困っていること
docker上でrailsの環境を構築しているのですが、上記写真のようにdocker-compose upを実行しすると" FATAL: database files are incompatible with server"または"The data directory was initialized by PostgreSQL version 10, which is not compatible with this version 11.1 (Debian 11.1-3.pgdg90+1)"と表示されます。
また別タブでターミナルを開きdocker-compose run web rails db:createを実行すると以下のように表示されました。
***:Rails-master ***$ docker-compose run web rails db:create Starting rails-master_db_1 ... done could not translate host name "db" to address: Name or service not known Couldn't create 'myapp_development' database. Please check your configuration. rails aborted!
#調べたこと
上記エラー文の"The data directory was initialized by PostgreSQL version 10, which is not compatible with this version 11.1 (Debian 11.1-3.pgdg90+1)"をコピペして調べたらリンク内容で得た情報を元に"rm -rf /usr/bin/pg && initdb /usr/bin/pg -E utf8"を実行しましたが
"-bash: initdb: command not found"と表示されました。
言葉足らずだったら申し訳ありません。
このエラーを解決する為に、何かご教授頂ければ幸いです。


回答1件
あなたの回答
tips
プレビュー