0
0

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 1 year has passed since last update.

Docker の実験(その3:ポート番号の設定)

Last updated at Posted at 2023-02-17

その2:コンテナの調査のつづき。

コンテナを停止する。

$ docker container stop funny_wu
funny_wu

ローカルホストのポート番号を 8080、名前を mynginx にしてみる。

$ docker container run -dt -p 8080:80 --name mynginx nginx
a985f26967a89a512ec1ad9d8b6a34552800f22f1d4b220e084ef7e7dc65eaa0

確認する。

$ docker container ps
CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS              PORTS                                   NAMES
a985f26967a8   nginx     "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:8080->80/tcp, :::8080->80/tcp   mynginx

netstat で、8080 番ポートが開いているか確認する。

$ netstat -ntlp
(No info could be read for "-p": geteuid()=20163 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:33905         0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp6       0      0 :::8080                 :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -

webからも確認する。
vm のグローバル IP の確認方法
(参考)
https://cloud.google.com/compute/docs/instances/view-ip-address?hl=ja#gcloud

$ gcloud compute instances list
$ gcloud compute instances describe <instance-name> --zone=asia-northeast1-b --format='get(networkInterfaces[0].accessConfigs[0].natIP)'
xxx.xxx.xxx.xxx

ちなみに、プロジェクトのデフォルトゾーンに存在しているインスタンスならば、ゾーンオプションは省略できる。

https://<IP_ADDR>:8080

タイムアウトする。これは、Firewall で、8080 番ポートが開いてないから。

Google Cloud で作成していた Firewall Rule で、ポートのところを修正する。

Protocols and ports:Specified protocols and ports:TCP:80,8080

webから再度確認する。

https://<IP_ADDR>:8080

確認できた。

その4:コンテナの停止および自動起動の設定につづく。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?