LoginSignup
1
1

More than 5 years have passed since last update.

Docker内のNode.jsサーバーでファイルの変更を検知して自動再起動

Last updated at Posted at 2018-10-09

docker-composeで構築した環境の中でNode製アプリを実行。
その際にコード修正後のアプリ自動再起動に苦労したのでメモ。

使用したライブラリ

  • Docker: version 18.03.1-ce, build 9ee9f40
  • docker-compose: version 1.21.1, build 5a3f1a3
  • nodemon: v1.18.4
  • node.js: v8.12.0

docker-compose.yml

念の為Volumeのマウント設定を併記。
ホストで修正したコードをコンテナ内に同期するために設定しています。

docker-compose.yml
services:
  app:
~~
    volumes:
      - ./node-app:/opt/node-app
~~

docker内でのnodemonの起動コマンド

$ nodemon -L app.js

-L がポイント。
legacyWatchオプションをONにしないとホストから同期したコードの変更を検知してくれない。
これにはまった。
https://github.com/remy/nodemon#application-isnt-restarting

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