3
3

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.

dockerodeからポートフォワードを指定してコンテナを起動する

Last updated at Posted at 2014-09-01

node.jsからDockerのRemote APIをいじくるラッパーとして使っているdockerode

コンテナの3000番ポートをホスト側の30000番ポートにマップしてnginxでリバースプロキシかませて外から見たいなと思ったので調べてみた。

ドキュメントにはcreateOptionやstartOptionを指定してね、と書いてあるけどdockerode自体のドキュメントにはそれは書いてなさげ。
本体のドキュメントを見て色々いじってみて、とりあえずこうすればいいのかなというのは見えてきた。

var Docker = require('dockerode');

var docker = new Docker({socketPath: '/var/run/docker.sock'});

docker.run(
	'イメージ名',
	['コンテナ', '起動で', '動かす', 'コマンド'],
	process.stdout,
	{
		'ExposedPorts': {'3000/tcp': {}}
	},
	{
		'PortBindings': {'3000/tcp': [{'HostPort': '30000'}]}
	},
	function (err, data, container) {
		//	起動するとここに来る
	}
);

コールバック関数の前にある2つのハッシュでそれぞれ

  • コンテナ作成時にTCPの3000番ポートを開ける
  • TCPの3000番ポートをホスト側の30000番ポートにマップする

という指定をしてあげればいいらしい

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?