1
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 3 years have passed since last update.

Docker超初級編 コンテナ構築とrailsのcreateとmigrate実行

Last updated at Posted at 2021-07-21

ビルド

docker-compose
calculate_calorie_app % docker-compose build
[+] Building 137.4s (16/16) FINISHED                                            
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 558B                                       0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/library/ruby:2.6.5              3.8s
 => [ 1/11] FROM docker.io/library/ruby:2.6.5@sha256:651078e89471c305676  57.2s
 => => resolve docker.io/library/ruby:2.6.5@sha256:651078e89471c30567685d  0.0s
 => => sha256:41ebfd3d2fd0de99b1c63aa36a507bf5555481d06e5 7.81MB / 7.81MB  9.1s
 => => sha256:b998346ba308e3362a85c7bf7faed28d0277c6820 10.00MB / 10.00MB  7.2s
 => => sha256:f15005b0235fa8bd31cc6988c4f2758016fe412d 50.38MB / 50.38MB  20.2s
 => => sha256:651078e89471c30567685dce4caa321adf1f846b353 1.65kB / 1.65kB  0.0s
 => => sha256:53560b05e51bfe022cc25a29086aa92dceb98523d38 2.00kB / 2.00kB  0.0s
 => => sha256:ad10dfbc638bf737789e277768d9cc49ddbef72b74d 7.13kB / 7.13kB  0.0s
 => => sha256:f01ec562c947a8ca1b168415da6a4a8f8920808f 51.79MB / 51.79MB  25.6s
 => => sha256:2447a2c119076510a07d71cfcec029fceac2e5 192.17MB / 192.17MB  47.0s
 => => sha256:1915e6344d7f76a07a4e6216b33683b8d6f6b544276f07 200B / 200B  21.4s
 => => extracting sha256:f15005b0235fa8bd31cc6988c4f2758016fe412d696e81ae  3.4s
 => => sha256:6ea7f301ab4557bbf8408fc56a27b9c5a1d8bd64 21.48MB / 21.48MB  28.7s
 => => extracting sha256:41ebfd3d2fd0de99b1c63aa36a507bf5555481d06e571d84  0.6s
 => => extracting sha256:b998346ba308e3362a85c7bf7faed28d0277c68203696134  0.4s
 => => sha256:0c79fcaf0109fa1c03573e177b1f6e19a9bd9f9a19ccde 144B / 144B  25.9s
 => => extracting sha256:f01ec562c947a8ca1b168415da6a4a8f8920808f9b5d6f42  3.9s
 => => extracting sha256:2447a2c119076510a07d71cfcec029fceac2e59eea21fc7b  8.6s
 => => extracting sha256:1915e6344d7f76a07a4e6216b33683b8d6f6b544276f079e  0.0s
 => => extracting sha256:6ea7f301ab4557bbf8408fc56a27b9c5a1d8bd648aef8b5b  0.7s
 => => extracting sha256:0c79fcaf0109fa1c03573e177b1f6e19a9bd9f9a19ccdef7  0.0s
 => [internal] load build context                                          0.1s
 => => transferring context: 345.96kB                                      0.0s
 => [ 2/11] RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -   10.5s
 => [ 3/11] RUN apt-get update -qq   && apt-get install -y nodejs --no-in  8.5s
 => [ 4/11] RUN npm install -g yarn                                        2.3s
 => [ 5/11] RUN mkdir /app                                                 0.3s
 => [ 6/11] WORKDIR /app                                                   0.0s
 => [ 7/11] COPY Gemfile /app/Gemfile                                      0.0s
 => [ 8/11] COPY Gemfile.lock /app/Gemfile.lock                            0.0s
 => [ 9/11] RUN gem install bundler && bundle install                     52.2s
 => [10/11] COPY yarn.lock /app/yarn.lock                                  0.0s
 => [11/11] RUN yarn install                                               0.6s
 => exporting to image                                                     1.8s
 => => exporting layers                                                    1.8s
 => => writing image sha256:b7114d4b4251e71bd943f5d19634d863e07381030f7ef  0.0s
 => => naming to docker.io/library/calculate_calorie_app_rails             0.0s

クリエイト

docker-compose
calculate_calorie_app % docker-compose exec rails bash
root@a31907816406:/app# rake db:create
Created database 'calculate_calorie_app_development'
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Couldn't create 'calculate_calorie_app_test' database. Please check your configuration.
rake aborted!
Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `initialize'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/mysql2_adapter.rb:24:in `new'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/mysql2_adapter.rb:24:in `mysql2_connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/connection_handling.rb:189:in `connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:126:in `create'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:185:in `block in create_current'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:479:in `block (2 levels) in each_current_configuration'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:476:in `each'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:476:in `block in each_current_configuration'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:475:in `each'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:475:in `each_current_configuration'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:184:in `create_current'
/usr/local/bundle/gems/activerecord-6.0.3.7/lib/active_record/railties/databases.rake:39:in `block (2 levels) in <main>'
/usr/local/bundle/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

マイグレート

コンテナ内で
root@a31907816406:/app# rake db:migrate
== 20210611011005 DeviseCreateUsers: migrating ================================
-- create_table(:users)
   -> 0.0205s
-- add_index(:users, :email, {:unique=>true})
   -> 0.0263s
-- add_index(:users, :reset_password_token, {:unique=>true})
   -> 0.0220s
== 20210611011005 DeviseCreateUsers: migrated (0.0705s) =======================

== 20210611115003 CreateProfiles: migrating ===================================
-- create_table(:profiles)
   -> 0.0276s
== 20210611115003 CreateProfiles: migrated (0.0278s) ==========================

== 20210612022515 CreateCircles: migrating ====================================
-- create_table(:circles)
   -> 0.0305s
== 20210612022515 CreateCircles: migrated (0.0323s) ===========================

== 20210616101834 CreateCookedFoods: migrating ================================
-- create_table(:cooked_foods)
   -> 0.0377s
== 20210616101834 CreateCookedFoods: migrated (0.0383s) =======================

== 20210620124333 CreateHomeCookedMeals: migrating ============================
-- create_table(:home_cooked_meals)
   -> 0.0248s
== 20210620124333 CreateHomeCookedMeals: migrated (0.0260s) ===================

== 20210623073049 CreateFridges: migrating ====================================
-- create_table(:fridges)
   -> 0.0199s
== 20210623073049 CreateFridges: migrated (0.0218s) ===========================

== 20210623073520 CreateCookings: migrating ===================================
-- create_table(:cookings)
   -> 0.0223s
== 20210623073520 CreateCookings: migrated (0.0225s) ==========================

== 20210627054917 CreateFoods: migrating ======================================
-- create_table(:foods)
   -> 0.0203s
== 20210627054917 CreateFoods: migrated (0.0204s) =============================

== 20210627063024 CreateCookingFoods: migrating ===============================
-- create_table(:cooking_foods)
   -> 0.0342s
== 20210627063024 CreateCookingFoods: migrated (0.0343s) ======================

== 20210703023622 CreateFoodStuffs: migrating =================================
-- create_table(:food_stuffs)
   -> 0.0245s
== 20210703023622 CreateFoodStuffs: migrated (0.0247s) ========================

root@a31907816406:/app# rake db:seed
root@a31907816406:/app# exit
exit
maedatakuo@maedatakudainoMacBook-Air calculate_calorie_app % docker-compose stop
Stopping calculate_calorie_app_db_1    ... done
Stopping calculate_calorie_app_rails_1 ... done
1
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
1
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?