LoginSignup
2
1

More than 3 years have passed since last update.

自分用メモ:Dockerのネットワーク設定

Last updated at Posted at 2019-08-06

Dockerの使いこなしを続けていますが、
ネットワーク設定で思った以上にハマった自分への健忘録

環境

  • Windows 10 Home
  • VMWare Workstation 14 Player
  • 仮想環境 CentOS 7
# uname -a
Linux localhost.localdomain 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

# docker -v
Docker version 19.03.1, build 74b1e89

やりたいこと

VMWorkstationで動くCentOS7をホストPCにした、
Docker centos:centos7でyum updateする。

そのためには、dockerコンテナ側から、
ホストPC側のネットワークにアクセスしたうえで、
いろいろポートがホスト-コンテナ間で選択的に空けたい。

結論

VMWorkstationを実行してるWindowsPC のファイアウォール設定を見直したら通った!

やったこと

https://www.memotansu.jp/docker/894/
により、Dockerのネットワーク設定・状態確認 方法を学び、

https://www.scriptlife.jp/contents/programming/2016/09/07/docker-can-not-connect/
により、外部と接続できない場合iptablesで、許可する方法を学び、

https://blog.mosuke.tech/entry/2014/09/20/180326/
により、CentOS7上でiptablesを設定する方法を学び、

hostPC
 # yum install iptables-services

 # systemctl status firewalld
 # systemctl stop firewalld
 # systemctl status firewalld
 # systemctl disable firewalld

 # systemctl enable iptables
 # systemctl start iptables
 # systemctl status iptables

 # iptables -t nat -A POSTROUTING -s 172.17.0.0/16 -j MASQUERADE
 # service iptables restart

 # docker exec -it test1 /bin/bash

で試してみたが、ダメ。

test1
 # curl https://www.google.com 
 # yum update 

これが通れば、勝ちなのだが。。。

さらに、
https://blog.sioyaki.com/entry/2017/02/19/154412
により、IPv4 forwarding is disabledエラー解決方法から、

hostPC
 # sudo sysctl -w net.ipv4.ip_forward=1

で試してみたが、ダメ。

もしやと思って、
上記までを実行した状態でWindows側のファイアウォール設定より、
プライベートネットワークを無効化したら通った!

さすがに無効化はやりすぎなので、

解決策として、Windows PC
コントロールパネル > システムとセキュリティ > Windows Defender ファイアウォール
詳細設定 から、

受信の規則 > 新しい規則... と 送信の規則 > 新しい規則...
で、
+ プログラム
+ VMWare Workstarion の実行ファイル vmplayer.exe を選択
+ 接続を許可する
+ ドメイン/プライベートにチェック ※パブリックは外しておく
+ 任意の名前と説明を記載して完了!

これで通った!

hostPC
[root@localhost ~]# docker exec -it test1 /bin/bash

[root@19c85c0e3052 /]# curl https://www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="ja"><head><meta content=・・・
・・・(以下略

[root@19c85c0e3052 /]# yum update
Determining fastest mirrors
 * base: ftp.yz.yamagata-u.ac.jp
 * extras: ftp.yz.yamagata-u.ac.jp
 * updates: ftp.yz.yamagata-u.ac.jp
base                                                                                                                                             | 3.6 kB  00:00:00
extras                                                                                                                                           | 3.4 kB  00:00:00
updates                                                                                                                                          | 3.4 kB  00:00:00
(1/4): extras/7/x86_64/primary_db                                                                                                                | 215 kB  00:00:03
(2/4): base/7/x86_64/group_gz                                                                                                                    | 166 kB  00:00:03
(3/4): base/7/x86_64/primary_db                                                                                                                  | 6.0 MB  00:00:05
(4/4): updates/7/x86_64/primary_db                                                                                                               | 7.4 MB  00:00:05
Resolving Dependencies
--> Running transaction check
・・・(以下略
2
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
2
1