4
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.

DockerでNode.jsの起動

4
Last updated at Posted at 2018-06-07

DockerでNode.jsを起動してみる

やり方は色々ありますが、公式イメージを使用するのが手軽なので今回はそれでやります。

手順

docker-compose ファイルを作成

  version: "2"
  services:
	node:
	  image: "node:latest"
	  user: "node"
	  working_dir: /home/node/app
	  environment:
	    - NODE_ENV=production
	  volumes:
	    - ../app:/home/node/app
	  expose:
	    - "3000"
	  ports:
	    - "3000:3000"
	  command: "npm run start"

※composeファイルの一つ上のディレクトリにアプリケーションフォルダ(app)を配置しマウントする設定にしています。
※ポート3000での接続を想定。

Dockerコンテナを起動

docker-compose up -d

まとめ

Dockerの基本的な説明は省きましたが、殆ど上記方法だけで簡単な環境は出来てしまいます。
改めてDocker便利だなぁ~と実感しつつ、Node.js起動して終わりではなんなので; 今度はアプリを動かしてみたいと思います。
TypeScriptも覚えなきゃと思っていたので、次は「Nest」のインストールと実行をやってみます。

4
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
4
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?