Linux

docker 네트워크 추가 하기

Naan 2021. 1. 28. 15:41
320x100

docker 를 이용해서 centos7 를 설치 해보자.

# docker run -itd --name centos7 centos:7


# docker exec -it centos7 /bin/bash

접속 해보면

# ifconfig 

를 이용해 IP 확인해보자.

하지만 centos7 이미지는 깡통이다. 아무것도 설치가 안되 있어 모두 설치 해줘야 한다.

# yum install -y net-tools

# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 172.17.0.5  netmask 255.255.0.0  broadcast 172.17.255.255

        ether 02:42:ac:11:00:05  txqueuelen 0  (Ethernet)

        RX packets 2657  bytes 12147479 (11.5 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 2321  bytes 155712 (152.0 KiB)

        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

        loop  txqueuelen 1000  (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

네트워크 하나만 떠 있다. 추가해주자.

# docker network create eth1_net
# docker network connect eth1_net centos7

# docker run -itd --name centos7 centos:7
다시 들어가서

# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.5  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:05  txqueuelen 0  (Ethernet)
        RX packets 2657  bytes 12147479 (11.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2321  bytes 155712 (152.0 KiB)
        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 172.18.255.255
        ether 02:42:ac:12:00:02  txqueuelen 0  (Ethernet)
        RX packets 7  bytes 586 (586.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

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (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

추가 된것을 확인 할 수 있다.

추가로 네트워크 끊는 방법은
# docker network disconnect eth1_net centos7

특정 IP로 추가 하고 싶으면
# docker network connect eth1_net --ip=192.168.0.55 centos7
이다.




320x100