docker network 추가 하기
# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:2 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 28791 bytes 77845139 (74.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20429 bytes 1352713 (1.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
네트워크가 기본으로 1개만 있다. 이걸 2개로 늘려보자.
현재 사용하고 있는 네트워크를 확인을 하면
# docker network ls
NETWORK ID NAME DRIVER SCOPE
af59a768c37d bridge bridge local
3a4141d898d5 host host local
cfe07ba02557 none null local
이렇게 나온다. 여기서 네트워크를 추가를 하자.
# docker network create --driver=bridge test-network
c027fc959deec81de81d57481185d2d38e23a0f5a899aaba80caaa7ae4511f64
# docker network ls
NETWORK ID NAME DRIVER SCOPE
af59a768c37d bridge bridge local
3a4141d898d5 host host local
c027fc959dee test-network bridge local
cfe07ba02557 none null local
네트워크가 추가 됐다.
이제 컨테이너에 등록되어 있는 장비에 네트워크를 추가 하자.
# docker network connect test-network centos7
# docker attach centos7
# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.2 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:2 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:00:02 txqueuelen 0 (Ethernet)
RX packets 28791 bytes 77845139 (74.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20429 bytes 1352713 (1.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.2 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe12:2 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:12:00:02 txqueuelen 0 (Ethernet)
RX packets 20 bytes 2266 (2.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7 bytes 578 (578.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
네트워크가 2개가 된것을 확인 할 수 있다.