Vagrant + CoreOSでポートフォワーディング
Vagrant + CoreOS な環境で、Dockerコンテナを起動して、ブラウザで確認することろまでいきます。
Vagrant と CoreOS のセットアップは省きます。
ゲストとホストでポートフォワーディング
config.rb.sample
をconfig.rb
にコピー- 80 => 8080 をポートフォワーディングします
$ cat config.rb forwarded_ports = { 1234 => 5678 }
vagrant up
もしくは vagrant reload
してポートフォワーディングできているのを確認します。
==> core-01: Forwarding ports... core-01: 1234 (guest) => 5678 (host) (adapter 1) core-01: 22 (guest) => 2222 (host) (adapter 1)
CoreOS で Dockerコンテナを起動
$ vagrant ssh
CentoOS 7 で nginx を起動する Docker コンテナイメージの作成
CentOS 7 の Dockerイメージを使用しています。
$ cat << EOS > Dockerfile FROM centos:7 RUN yum install epel-release -y RUN yum install nginx -y RUN yum clean all EXPOSE 80 CMD ["/usr/sbin/nginx", "-g", "daemon off;"] EOS
Dockerコンテナを起動します。
$ docker run -t -i -d -p 1234:80 <IMAGE ID>
CoreOS から Dockerコンテナを確認
$ curl -I http://localhost:1234 HTTP/1.1 200 OK Server: nginx/1.12.2 Date: Tue, 19 Dec 2017 00:26:38 GMT Content-Type: text/html Content-Length: 3700 Last-Modified: Wed, 18 Oct 2017 08:08:18 GMT Connection: keep-alive ETag: "59e70bf2-e74" Accept-Ranges: bytes
ホストマシンから確認
$ curl -I http://localhost:5678 HTTP/1.1 200 OK Server: nginx/1.12.2 Date: Tue, 19 Dec 2017 00:27:46 GMT Content-Type: text/html Content-Length: 3700 Last-Modified: Wed, 18 Oct 2017 08:08:18 GMT Connection: keep-alive ETag: "59e70bf2-e74" Accept-Ranges: bytes
よさそうです。