質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

2回答

889閲覧

Rails Docker docker-compose db:create db:migrate 出来ない

UMAweb1

総合スコア5

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2020/01/01 11:24

Docker docker-compose db:create db:migrate 出来ない

既存アプリケーションの開発環境にdockerを適用させようと思ったのですが、

docker-compose build

の後に、

docker-compose run web rails db:create db:migrate や docker-compose run web bundle exec rails db:create db:migrate

といったコマンドを叩いても、

Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"rails\": executable file not found in $PATH": unknown

と表示されてしまいます。

docker-compose up

上記コマンドは通り、ページを表示しようとしてくれています(migrateされていないので表示自体はできませんが)

色々な記事を参考にしてみたのですが、
どれもうまくいかず途方に暮れている状態です、、、。
もし、これが原因かもしれないなどあれば、ご教示いただけますと幸いです。

開発環境

ruby2.5.5
rails 5.2.4.1
docker 19.03.1
windows 10 home

現状

gemfile

1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.5.5' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 5.2.4' 8# Use sqlite3 as the database for Active Record 9gem 'sqlite3' 10# Use postgresql as the database for Active Record 11gem 'pg', '~> 0.18' 12# Use Puma as the app server 13gem 'puma', '~> 3.11' 14# Use SCSS for stylesheets 15gem 'sass-rails', '~> 5.0' 16# Use Uglifier as compressor for JavaScript assets 17gem 'uglifier', '>= 1.3.0' 18# See https://github.com/rails/execjs#readme for more supported runtimes 19# gem 'mini_racer', platforms: :ruby 20 21# Use CoffeeScript for .coffee assets and views 22gem 'coffee-rails', '~> 4.2' 23# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 24# gem 'turbolinks', '~> 5' 25# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 26gem 'jbuilder', '~> 2.5' 27# Use Redis adapter to run Action Cable in production 28# gem 'redis', '~> 4.0' 29# Use ActiveModel has_secure_password 30# gem 'bcrypt', '~> 3.1.7' 31 32# Use ActiveStorage variant 33# gem 'mini_magick', '~> 4.8' 34 35# Use Capistrano for deployment 36# gem 'capistrano-rails', group: :development 37 38# Reduces boot times through caching; required in config/boot.rb 39gem 'bootsnap', '>= 1.1.0', require: false 40 41group :development, :test do 42 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 43 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 44 gem 'pry-rails' 45 gem 'pry-byebug' 46 gem 'pry-doc' 47 gem 'better_errors','2.5.1' 48 gem 'binding_of_caller','0.8.0' 49 gem 'rspec-rails','3.9.0' 50 gem 'factory_bot_rails','~> 5.1.1' 51end 52 53group :development do 54 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 55 gem 'web-console', '>= 3.3.0' 56 gem 'listen', '>= 3.0.5', '< 3.2' 57 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 58 gem 'spring' 59 gem 'spring-watcher-listen', '~> 2.0.0' 60end 61

Dockerfile

1FROM ruby:2.5.5 2 3RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/* 4RUN apt-get update && apt-get install -y postgresql-client --no-install-recommends && rm -rf /var/lib/apt/lists/* 5RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs 6 7WORKDIR /myapp 8 9ADD Gemfile /myapp/Gemfile 10ADD Gemfile.lock /myapp/Gemfile.lock 11 12RUN gem install bundler 13RUN bundle install 14 15ADD . /myapp 16 17CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

entrypointsh

1#!/bin/bash 2set -e 3 4# Remove a potentially pre-existing server.pid for Rails. 5rm -f /myapp/tmp/pids/server.pid 6 7# Then exec the container's main process (what's set as CMD in the Dockerfile). 8exec "$@"

dockercomposeyml

1version: '3' 2services: 3 db: 4 image: postgres 5 volumes: 6 - ./tmp/db:/var/lib/postgresql/data 7 web: 8 build: 9 context: . 10 dockerfile: Dockerfile 11 command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 12 volumes: 13 - .:/myapp 14 ports: 15 - "3000:3000" 16 depends_on: 17 - db

databeseyml

1default: &default 2 adapter: postgresql 3 encoding: unicode 4 host: db 5 username: postgres 6 password: 7 pool: 5 8 9development: 10 <<: *default 11 database: myapp_development 12 13 14test: 15 <<: *default 16 database: myapp_test

他、必要情報などあれば伝えさせていただければと思います。
無駄な情報も多いかもしれませんが、何卒ご容赦頂ければ幸いです。
よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

下記を削除することで、dbが起動しdb:create等が可能となりました。
ただこれでは永続化が出来ない状況のため色々方法を探したいと思います。

volumes: - ./tmp/db:/var/lib/postgresql/data

投稿2020/01/07 05:45

UMAweb1

総合スコア5

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

dbとwebのコンテナが分かれているので、dbをバックグラウンドで起動したままrun webをする必要があります。

投稿2020/01/02 16:29

mariguranule

総合スコア204

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

UMAweb1

2020/01/05 11:52

ご回答誠にありがとうございます。 返信遅れてしまい申し訳ございません。 仰る通り、dbが起動されていないようなのですが、コマンドを叩いてみたり、再度アプリの作り直しから行っても、以下のエラーが発生する状況です、、。 db_1 | **************************************************** db_1 | WARNING: No password has been set for the database. db_1 | This will allow anyone with access to the db_1 | Postgres port to access your database. In db_1 | Docker's default configuration, this is db_1 | effectively any other container on the same db_1 | system. db_1 | db_1 | Use "-e POSTGRES_PASSWORD=password" to set db_1 | it in "docker run". db_1 | **************************************************** db_1 | The files belonging to this database system will be owned by user "postgres". db_1 | This user must also own the server process. db_1 | db_1 | The database cluster will be initialized with locale "en_US.utf8". db_1 | The default database encoding has accordingly been set to "UTF8". db_1 | The default text search configuration will be set to "english". db_1 | db_1 | Data page checksums are disabled. db_1 | db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok db_1 | creating subdirectories ... ok db_1 | selecting dynamic shared memory implementation ... posix db_1 | selecting default max_connections ... 20 db_1 | selecting default shared_buffers ... 400kB db_1 | selecting default time zone ... Etc/UTC db_1 | creating configuration files ... ok db_1 | running bootstrap script ... 2020-01-04 03:14:38.022 UTC [80] FATAL: data directory "/var/lib/postgresql/data" has wrong ownership db_1 | 2020-01-04 03:14:38.022 UTC [80] HINT: The server must be started by the user that owns the data directory. db_1 | child process exited with exit code 1 db_1 | initdb: removing contents of data directory "/var/lib/postgresql/data"
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問