今回はDockerでRails環境を立ち上げた方向けに、開発環境の起動、停止、削除を説明していきます。
一緒に学習しましょう。
DockerでRailsの起動
起動コマンドは以下です。
以下のコマンドをdocker-compose.ymlがあるフォルダに移動して実行してください。
「-d」オプションをつけると細かいログは表示されません。
$ docker-compose up -d
waitingmuch_db_1 is up-to-date
waitingmuch_web_1 is up-to-date
こうして自分が指定したlocalhostのポートにアクセスするとRailsのページが表示されます。
http://localhost:3000/
DockerでRailsの停止
以下のコマンドで開発環境が止まって、アクセスできなくなります。
この状態ではコンテナは存在しています。
$ docker-compose stop
Stopping waitingmuch_web_1 ... done
Stopping waitingmuch_db_1 ... done
コンテナの削除
コンテナを削除するには以下のコマンドになります。
$ docker-compose down
Removing waitingmuch_web_run_2e3662db6a41 ... done
Removing waitingmuch_web_1 ... done
Removing waitingmuch_web_run_ced211573730 ... done
Removing waitingmuch_db_1 ... done
Removing network waitingmuch_default
ログの確認
サーバー起動時に「-d」オプションをつけないで起動すると、以下のようにログが出ます。
$ docker-compose up
waitingmuch_db_1 is up-to-date
waitingmuch_web_1 is up-to-date
Attaching to waitingmuch_db_1, waitingmuch_web_1
db_1 | 2021-02-06 15:38:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started.
db_1 | 2021-02-06 15:39:00+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2021-02-06 15:39:00+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.31-1debian10 started.
db_1 | 2021-02-06T15:39:00.516940Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2021-02-06T15:39:00.520564Z 0 [Note] mysqld (mysqld 5.7.31) starting as process 1 ...
db_1 | 2021-02-06T15:39:00.527319Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1 | 2021-02-06T15:39:00.527400Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2021-02-06T15:39:00.527433Z 0 [Note] InnoDB: Uses event mutexes
db_1 | 2021-02-06T15:39:00.527502Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1 | 2021-02-06T15:39:00.527527Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1 | 2021-02-06T15:39:00.527553Z 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2021-02-06T15:39:00.528832Z 0 [Note] InnoDB: Number of pools: 1
db_1 | 2021-02-06T15:39:00.529469Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1 | 2021-02-06T15:39:00.534510Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | 2021-02-06T15:39:00.566197Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2021-02-06T15:39:00.575208Z 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 | 2021-02-06T15:39:00.600976Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1 | 2021-02-06T15:39:00.633912Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2021-02-06T15:39:00.634107Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1 | 2021-02-06T15:39:00.691069Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1 | 2021-02-06T15:39:00.693182Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1 | 2021-02-06T15:39:00.693295Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1 | 2021-02-06T15:39:00.694759Z 0 [Note] InnoDB: 5.7.31 started; log sequence number 12578224
db_1 | 2021-02-06T15:39:00.695254Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2021-02-06T15:39:00.695370Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1 | 2021-02-06T15:39:00.704837Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1 | 2021-02-06T15:39:00.704891Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1 | 2021-02-06T15:39:00.706129Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2021-02-06T15:39:00.706222Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1 | 2021-02-06T15:39:00.708130Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1 | 2021-02-06T15:39:00.708490Z 0 [Note] IPv6 is available.
db_1 | 2021-02-06T15:39:00.708578Z 0 [Note] - '::' resolves to '::';
db_1 | 2021-02-06T15:39:00.708624Z 0 [Note] Server socket created on IP: '::'.
db_1 | 2021-02-06T15:39:00.711642Z 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 | 2021-02-06T15:39:00.712299Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210206 15:39:00
db_1 | 2021-02-06T15:39:00.734828Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2021-02-06T15:39:00.735370Z 0 [Note] mysqld: ready for connections.
db_1 | Version: '5.7.31' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
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 | Puma starting in single mode...
web_1 | * Version 3.12.6 (ruby 2.3.6-p384), 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
終了する際は「control+c」で終了できます。この場合サーバーPIDファイルが残ります。
再度起動した際にはpidファイルが原因でエラーが発生することがあるので、こちらを削除して再度立ち上げてください。
$ rm tmp/pids/server.pid
コメント