2
2

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

Amazon EC2のDockerコンテナで実行しているアプリが停止していた

Last updated at Posted at 2018-11-12

前提

監視するほどのものでもなかったので特にCloudWatch等での監視は行っていない。

気づき

rsyslog・httpd・nginx・mysqld・php-fpm・memcached等はsystemdでの自動起動の設定の一般的ですが、Dockerコンテナの癖はついていなかった。
監視するほどのものでもなくてもDockerでアプリケーションを作る場合はコンテナ自体の自動起動の設定は必要。

事象

ある日アプリケーションが停止していた。

Dockerのコンテナを見たら停止していた。

システムログ

# view /var/log/messages

容量等も問題なかった。

Dockerのlogも問題なかった。

直近のreboot

# last reboot

何故かrebootが行われていた。

AWSマネジメントコンソールでインスタンスの完了したイベントを確認してみると、rebootが行われた時間にsystem-rebootがスケジュールされていた。

AWSで勝手にインスタンスが再起動されていた様子。

監視するリソースが無いので、Dockerコンテナが自動起動するようにしなければいけない。

Dockerコンテナの自動起動を設定する

動作確認はローカル環境にAmazonLinux2を作成して確認を行った。

Amazon Linuxのローカル環境を作成する

Running Docker Containers with Systemd

vi /etc/systemd/system/docker.app.service
/etc/systemd/system/docker.app.service
[Unit]
Description=App Container
After=docker.service
Requires=docker.service

[Service]
Restart=always
ExecStart=-/usr/bin/docker start app

[Install]
WantedBy=multi-user.target
# systemctl enable docker.app.service

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.app.service to /etc/systemd/system/docker.app.service.

これを設定後rebootするとappコンテナが起動していたのでとりあえずこれでOK。

disableにしたらコンテナが起動しないことも確認してみた。

# systemctl disable docker.app.service

Removed symlink /etc/systemd/system/multi-user.target.wants/docker.app.service.

当然ですが、rebootするとappコンテナは起動しない。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?