カクカクしかじか...

無休→無給→Web系エンジニアのブログ

Docker入門 - Ruby2.5.1 x Rails5.2 x MySQL5.7 -

はじめに

はじめまして、fuqdaです。
今回はローカル開発環境での開発しかないDocker初心者の自分が
Dockerを使ってRailsの動作環境を作ってみようと思います。
なお本稿はDockerの詳しい解説よりもDockerに興味のある
自分のような初心者の方が動かせるようになるところをゴールに進めてます。

前提

  • Macユーザーの方
  • Docker ToolboxというDockerを扱えるものが他にありますがそちらは使いません。

対象者

  • Dockerに興味あるけど触れたことないDocker初心者の方
  • Ruby on Railsを触ったことがある方

今回やること

  • Docker for Macが正常にインストールされたことの確認
  • 開発に関連するDockerのコマンドの一部の確認
  • Docker環境でRailsを動かすこと

今回やらないこと

Docker for Macのインストール

MacでDockerを動かすために今回はDockerを作っている
Docker社純正のDocker for Macを使います。
まず公式サイトからダウンロードしましょう。 image.png

DockerでHello,worldしてみる

Docker for Macがインストール出来たら、Dockerを介してHello,worldをターミナル上に表示してみましょう。以下のコマンドをターミナルで実行してみます。

$ docker run hello-world

実行結果

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:9db522fd99adf8b84fc170fff8fde07d3b31194ecaf86141350a264fdcf5bccc
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

ちょこっと内容を解説

Hello from Docker! が表示されていれば、Dockerが正常に動作していることになります。
docker run イメージ名 を指定することで今回指定した hello-world というDockerイメージの中の Hello from Docker! を表示されるコマンドが実行されました。

Dockerのイメージにどういったものがあるのかは各種イメージをホスティングするDocker Hubというサイト上で検索することが出来ます。
Dockerイメージを正確に表現出来ているのか分かりませんが、個人的にJavaScriptのnpmライブラリやgemのようなイメージで理解しています。

またターミナルには Unable to find image 'hello-world:latest' locally と表示されていましたが、ローカルにコマンドの引数に指定したイメージがまだ無いということを示しています。
ローカルの実行環境にまだそのイメージが無い場合リモートのDockerイメージをホスティングしているDocker Hubに指定されたイメージを探しに行きます。今回はリモートにそのイメージが見つかったのでそれをローカルに落としてコマンドを実行した形になります。

エラー困った時マニュアル①

docker run イメージ名でリモートからイメージを取得出来ない

docker run hello-world のようなリモートとつなぐdockerコマンドを実行した際に以下のようなエラーメッセージが出て、リモートのDocerイメージが取得出来ない場合があります。

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: unauthorized: incorrect username or password.
See 'docker run --help'.

リモートのDockerイメージの取得先にアクセス出来ていないということなので以下のコマンドでログインしましょう。ちなみにDocker HubやDocker for Mac上でログインしているように見えてもdockerコマンドの判定に関わるログインとは別ものなので注意です。

$ docker login
Authenticating with existing credentials...
Stored credentials invalid or expired
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username (登録したメールアドレス): 登録したユーザーネームを入力する
Password: Docker Hubで登録したパスワードを入力する
Login Succeeded

Docker Hubでのイメージの見つけ方

サイトトップの虫眼鏡のマークから検索出来ます。 image.png

「hello-world」というイメージが検索結果にヒットしました。 image.png

「hello-world」のイメージをクリックしてみると詳細を見ることが出来ます。 image.png

TAGSと書いてあるタブをクリックするとそのDockerイメージのバージョンなどのバリエーションをチェック出来ます。なおRubyのDockerイメージの場合も2.3.62.5.1などの様々なバージョンのイメージをTAGSから確認出来ます。 image.png

まずDockerとRailsアプリの準備をする

こちらの講座を参考にしました。 https://www.udemy.com/rails-kj/

なお、上記の講座はRuby(2.3.6)とRails(5.0系)とバージョンが古かったためRuby(2.5.1)とRails(5.2.2)にバージョンアップしました。 上記の講座のファイルを元にバージョンアップで起こるエラーを解消して実行したものが以下のリポジトリにあります。今回は以下のリポジトリを完成として手順を進めていこうと思います。

完成形 https://github.com/Shigeyuki-fukuda/Docker-Rails

手順①ディレクトリとファイルを準備する

# 開発用のワークスペースディレクトリがあるならその下で
$ mkdir -p docker-rail; cd docker-rail
# 以下は/docker-railsディレクトリ内
# Dockerfileとdocker-compose.ymlとGemfile、Gemfile.lockを作成する
$ touch Dockerfile
$ touch docker-compose.yml
$ touch Gemfile
$ touch Gemfile.lock

手順②ファイルを以下のように編集

Dockerfile

FROM ruby:2.5.1
RUN apt-get update -qq && apt-get install -y build-essential nodejs
RUN mkdir /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN gem install bundler
RUN bundle install
COPY . /app

docker-compose.yml

version: '3'
services:
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/app
    ports:
      - 3000:3000
    depends_on:
      - db
    tty: true
    stdin_open: true
  db:
    image: mysql:5.7
    volumes:
      - db-volume:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
volumes:
  db-volume:

Gemfile

source 'https://rubygems.org'
gem 'rails'

Gemfile.lock

# 空でOK

Dockerを使ったRails環境をローカルに作成する

$ docker-compose run web rails new . --force --database=mysql

開発に使用する主なDockerコマンドを確認してみる

  • 以降のコマンドは全てdocker-compose.ymlと同じディレクトリで実行する前提で行います。

docker-compose up -dコマンド

  • 現在のディレクトリを起点にdocker-compose.ymlに記載したコンテナを起動するコマンドです。
  • Railsサーバー起動のrails sコマンドのような理解で良さそうです。
$ docker-compose up -d
docker-rails_db_1 is up-to-date # docker-railsの部分はアプリケーション名に置き換えてください
Creating docker-rails_web_1 ... done

コンテナの起動を確認するコマンド

docker-compose ps

$ docker-compose ps
       Name                     Command               State           Ports
------------------------------------------------------------------------------------
docker-rails_db_1    docker-entrypoint.sh mysqld      Up      3306/tcp, 33060/tcp
docker-rails_web_1   bundle exec rails s -p 300 ...   Up      0.0.0.0:3000->3000/tcp

コンテナを停止するコマンド

docker-compose stop

$ docker-compose stop
Stopping docker-rails_web_1 ... done
Stopping docker-rails_db_1  ... done

コンテナを削除するコマンド

  • 基本的に開発中は停止コマンドだけでOKですが削除したい場合は下記を実行しましょう。
$ docker-compose down
Stopping docker-rails_db_1 ... done
Removing docker-rails_web_run_279aba230fd4 ... done
Removing docker-rails_web_1                ... done
Removing docker-rails_web_run_b1f660570d0d ... done
Removing docker-rails_db_1                 ... done

開発環境のデータベースを作成するコマンド

docker-compose run コンテナのサービス名 bundle exec rails db:create

  • ここでのコンテナ名はdocker-compose.ymlで指定したRubyを含むコンテナのサービス名を指定します。
  • 自分の場合はdocker-compose.ymlのRubyを含むアプリケーション側のコンテナ名をwebとしたので、docker-compose run web bundle exec rails db:createになります。

通常のローカル環境のようにサーバーにアクセスした際のアクセスログを確認したい場合のサーバー起動コマンド

docker-compose up

  • docker-compose up -d-dオプションを付けないで実行した場合
$ docker-compose up
Starting docker-rails_db_1 ... done
Starting docker-rails_web_1 ... done
Attaching to docker-rails_db_1, docker-rails_web_1
db_1   | 2019-01-02T01:37:41.619885Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1   | 2019-01-02T01:37:41.621948Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 1 ...
db_1   | 2019-01-02T01:37:41.625431Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1   | 2019-01-02T01:37:41.625489Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1   | 2019-01-02T01:37:41.625515Z 0 [Note] InnoDB: Uses event mutexes
db_1   | 2019-01-02T01:37:41.625530Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1   | 2019-01-02T01:37:41.625542Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1   | 2019-01-02T01:37:41.625557Z 0 [Note] InnoDB: Using Linux native AIO
db_1   | 2019-01-02T01:37:41.625785Z 0 [Note] InnoDB: Number of pools: 1
db_1   | 2019-01-02T01:37:41.625928Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1   | 2019-01-02T01:37:41.628651Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1   | 2019-01-02T01:37:41.643307Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1   | 2019-01-02T01:37:41.646290Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1   | 2019-01-02T01:37:41.659044Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1   | 2019-01-02T01:37:41.660430Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 12371209
db_1   | 2019-01-02T01:37:41.660487Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 12371218
db_1   | 2019-01-02T01:37:41.660505Z 0 [Note] InnoDB: Database was not shutdown normally!
db_1   | 2019-01-02T01:37:41.660517Z 0 [Note] InnoDB: Starting crash recovery.
db_1   | 2019-01-02T01:37:41.778166Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
db_1   | 2019-01-02T01:37:41.778245Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1   | 2019-01-02T01:37:41.778316Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1   | 2019-01-02T01:37:41.808981Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1   | 2019-01-02T01:37:41.809973Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1   | 2019-01-02T01:37:41.809992Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1   | 2019-01-02T01:37:41.810368Z 0 [Note] InnoDB: Waiting for purge to start
db_1   | 2019-01-02T01:37:41.860636Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 12371218
db_1   | 2019-01-02T01:37:41.860842Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1   | 2019-01-02T01:37:41.861074Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1   | 2019-01-02T01:37:41.862366Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190102  1:37:41
db_1   | 2019-01-02T01:37:41.864706Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1   | 2019-01-02T01:37:41.864890Z 0 [Warning] CA certificate ca.pem is self signed.
db_1   | 2019-01-02T01:37:41.866588Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1   | 2019-01-02T01:37:41.866629Z 0 [Note] IPv6 is available.
db_1   | 2019-01-02T01:37:41.866650Z 0 [Note]   - '::' resolves to '::';
db_1   | 2019-01-02T01:37:41.866672Z 0 [Note] Server socket created on IP: '::'.
db_1   | 2019-01-02T01:37:41.870437Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1   | 2019-01-02T01:37:41.871884Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.871921Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.871942Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.871978Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.871993Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.872017Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.882359Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.883166Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.895242Z 0 [Note] Event Scheduler: Loaded 0 events
db_1   | 2019-01-02T01:37:41.895931Z 0 [Note] mysqld: ready for connections.
db_1   | Version: '5.7.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
web_1  | => Booting Puma
web_1  | => Rails 5.2.2 application starting in development
web_1  | => Run `rails server -h` for more startup options
web_1  | Puma starting in single mode...
web_1  | * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
web_1  | * Min threads: 5, max threads: 5
web_1  | * Environment: development
web_1  | * Listening on tcp://0.0.0.0:3000
web_1  | Use Ctrl-C to stop

なお、-dオプションなしで実行した場合には通常のrails sの時と同様にctrl+cでサーバーを停止出来ます。

エラー困った時マニュアル②

docker-compose upでサーバー起動したが、A server is already running. Check /app/tmp/pids/server.pid. とエラーが出る

$ docker-compose up
Starting docker-rails_db_1 ... done
Starting docker-rails_web_1 ... done
Attaching to docker-rails_db_1, docker-rails_web_1
db_1   | 2019-01-01T15:00:42.576652Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1   | 2019-01-01T15:00:42.578027Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 1 ...
db_1   | 2019-01-01T15:00:42.582392Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1   | 2019-01-01T15:00:42.582450Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1   | 2019-01-01T15:00:42.582465Z 0 [Note] InnoDB: Uses event mutexes
db_1   | 2019-01-01T15:00:42.582477Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1   | 2019-01-01T15:00:42.582492Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1   | 2019-01-01T15:00:42.582558Z 0 [Note] InnoDB: Using Linux native AIO
db_1   | 2019-01-01T15:00:42.582778Z 0 [Note] InnoDB: Number of pools: 1
db_1   | 2019-01-01T15:00:42.582915Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1   | 2019-01-01T15:00:42.584290Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1   | 2019-01-01T15:00:42.593417Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1   | 2019-01-01T15:00:42.595893Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1   | 2019-01-01T15:00:42.607478Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1   | 2019-01-01T15:00:42.618107Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1   | 2019-01-01T15:00:42.618210Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1   | 2019-01-01T15:00:42.652456Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1   | 2019-01-01T15:00:42.653903Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1   | 2019-01-01T15:00:42.653934Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1   | 2019-01-01T15:00:42.654612Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 12370866
db_1   | 2019-01-01T15:00:42.655658Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1   | 2019-01-01T15:00:42.657771Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1   | 2019-01-01T15:00:42.659046Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190101 15:00:42
db_1   | 2019-01-01T15:00:42.669586Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1   | 2019-01-01T15:00:42.669914Z 0 [Warning] CA certificate ca.pem is self signed.
db_1   | 2019-01-01T15:00:42.672580Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1   | 2019-01-01T15:00:42.672674Z 0 [Note] IPv6 is available.
db_1   | 2019-01-01T15:00:42.672700Z 0 [Note]   - '::' resolves to '::';
db_1   | 2019-01-01T15:00:42.672720Z 0 [Note] Server socket created on IP: '::'.
db_1   | 2019-01-01T15:00:42.674987Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1   | 2019-01-01T15:00:42.676201Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-01T15:00:42.676383Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-01T15:00:42.676446Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-01T15:00:42.676492Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-01T15:00:42.676511Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-01T15:00:42.676540Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-01T15:00:42.682399Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-01T15:00:42.682459Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-01T15:00:42.690773Z 0 [Note] Event Scheduler: Loaded 0 events
db_1   | 2019-01-01T15:00:42.691047Z 0 [Note] mysqld: ready for connections.
db_1   | Version: '5.7.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
web_1  | /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
web_1  | /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
web_1  | => Booting Puma
web_1  | => Rails 5.0.0.1 application starting in development on http://0.0.0.0:3000
web_1  | => Run `rails server -h` for more startup options
web_1  | /usr/local/bundle/gems/activesupport-5.0.0.1/lib/active_support/core_ext/numeric/conversions.rb:138: warning: constant ::Fixnum is deprecated
web_1  | A server is already running. Check /app/tmp/pids/server.pid.
web_1  | Exiting
docker-rails_web_1 exited with code 1

以下のように事前にサーバーが起動していないことを確認しても、たまにプロセスが残っている場合にプロセスが残っているという先述のエラーが発生することがあります。

$ docker-compose ps
       Name                     Command                State     Ports
----------------------------------------------------------------------
docker-rails_db_1    docker-entrypoint.sh mysqld      Exit 137
docker-rails_web_1   bundle exec rails s -p 300 ...   Exit 137

そんな時はserver.pidというサーバー起動時に作られるファイルを削除しましょう。

$ rm tmp/pids/server.pid

もう一度試して見ると

$ docker-compose up
Starting docker-rails_db_1 ... done
Starting docker-rails_web_1 ... done
Attaching to docker-rails_db_1, docker-rails_web_1
db_1   | 2019-01-02T01:37:41.619885Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1   | 2019-01-02T01:37:41.621948Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 1 ...
db_1   | 2019-01-02T01:37:41.625431Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1   | 2019-01-02T01:37:41.625489Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1   | 2019-01-02T01:37:41.625515Z 0 [Note] InnoDB: Uses event mutexes
db_1   | 2019-01-02T01:37:41.625530Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1   | 2019-01-02T01:37:41.625542Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1   | 2019-01-02T01:37:41.625557Z 0 [Note] InnoDB: Using Linux native AIO
db_1   | 2019-01-02T01:37:41.625785Z 0 [Note] InnoDB: Number of pools: 1
db_1   | 2019-01-02T01:37:41.625928Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1   | 2019-01-02T01:37:41.628651Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1   | 2019-01-02T01:37:41.643307Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1   | 2019-01-02T01:37:41.646290Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1   | 2019-01-02T01:37:41.659044Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1   | 2019-01-02T01:37:41.660430Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 12371209
db_1   | 2019-01-02T01:37:41.660487Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 12371218
db_1   | 2019-01-02T01:37:41.660505Z 0 [Note] InnoDB: Database was not shutdown normally!
db_1   | 2019-01-02T01:37:41.660517Z 0 [Note] InnoDB: Starting crash recovery.
db_1   | 2019-01-02T01:37:41.778166Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
db_1   | 2019-01-02T01:37:41.778245Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1   | 2019-01-02T01:37:41.778316Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1   | 2019-01-02T01:37:41.808981Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1   | 2019-01-02T01:37:41.809973Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1   | 2019-01-02T01:37:41.809992Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1   | 2019-01-02T01:37:41.810368Z 0 [Note] InnoDB: Waiting for purge to start
db_1   | 2019-01-02T01:37:41.860636Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 12371218
db_1   | 2019-01-02T01:37:41.860842Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1   | 2019-01-02T01:37:41.861074Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1   | 2019-01-02T01:37:41.862366Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190102  1:37:41
db_1   | 2019-01-02T01:37:41.864706Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1   | 2019-01-02T01:37:41.864890Z 0 [Warning] CA certificate ca.pem is self signed.
db_1   | 2019-01-02T01:37:41.866588Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1   | 2019-01-02T01:37:41.866629Z 0 [Note] IPv6 is available.
db_1   | 2019-01-02T01:37:41.866650Z 0 [Note]   - '::' resolves to '::';
db_1   | 2019-01-02T01:37:41.866672Z 0 [Note] Server socket created on IP: '::'.
db_1   | 2019-01-02T01:37:41.870437Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1   | 2019-01-02T01:37:41.871884Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.871921Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.871942Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.871978Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.871993Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.872017Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.882359Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.883166Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1   | 2019-01-02T01:37:41.895242Z 0 [Note] Event Scheduler: Loaded 0 events
db_1   | 2019-01-02T01:37:41.895931Z 0 [Note] mysqld: ready for connections.
db_1   | Version: '5.7.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
web_1  | => Booting Puma
web_1  | => Rails 5.2.2 application starting in development
web_1  | => Run `rails server -h` for more startup options
web_1  | Puma starting in single mode...
web_1  | * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
web_1  | * Min threads: 5, max threads: 5
web_1  | * Environment: development
web_1  | * Listening on tcp://0.0.0.0:3000
web_1  | Use Ctrl-C to stop

これでOKです。

開発環境URLにアクセスしてみる

先ほどの docker-compose upコマンドを実行し、サーバーが起動した状態でlocalhost:3000にアクセスしてみましょう。以下の画面が表示されれば成功です。

image.png