728x90
반응형
1. 네트워크 bridge 생성
- master90
docker network create --driver bridge devops
docker network create --driver bridge db
- docker 95
docker network create --driver bridge front
docker network create --driver bridge backend
1-2 Bridge 별 대역대
master90
# docker inspect devops | grep -i subnet
"Subnet": "172.22.0.0/16",
# docker inspect db | grep -i subnet
"Subnet": "172.23.0.0/16",
docker95
# docker inspect backend | grep -i subnet
"Subnet": "172.21.0.0/16",
# docker inspect front | grep -i subnet
"Subnet": "172.20.0.0/16",
2. 생성한 Bridge에 연결하는 컨테이너 생성
- master90
# docker run -dit --name DB01 --network db ubuntu:14.04 /bin/bash
# docker run -dit --name DB02 --network db ubuntu:14.04 /bin/bash
# docker run -dit --name Devops01 --network devops ubuntu:14.04 /bin/bash
# docker run -dit --name Devops02 --network devops ubuntu:14.04 /bin/bash
- docker 95
# docker run -dit --name Front01 --network front ubuntu:14.04 /bin/bash
# docker run -dit --name Front02 --network front ubuntu:14.04 /bin/bash
# docker run -dit --name BACK01 --network backend ubuntu:14.04 /bin/bash
# docker run -dit --name BACK02 --network backend ubuntu:14.04 /bin/bash
3. veth 페어 생성 및 호스트 네임스페이스 연결
# 네임스페이스 생성
ip netns add ns
# veth 페어 생성
ip link add ceth0 type veth peer name veth0
ip link add ceth1 type veth peer name veth1
# veth의 한쪽 끝을 네임스페이스에 연결
ip link set ceth0 netns ns
ip link set ceth1 netns ns
# master90
brctl addif br-$(docker network inspect -f '{{.Id}}' db) veth0
brctl addif br-$(docker network inspect -f '{{.Id}}' devops) veth1
# docker95
brctl addif br-$(docker network inspect -f '{{.Id}}' front) veth0
brctl addif br-$(docker network inspect -f '{{.Id}}' backend) veth1
# veth 인터페이스 활성화
ip link set veth0 up
ip link set veth1 up
4. 네임스페이스 내에서 인터페이스 활성화 및 IP 설정
네임스페이스(ns) 내부에서 ceth0 과 ceth1에 ip 주소를 설정하고 활성화 합니다.
ip netns exec ns ip addr add 192.168.1.10/24 dev ceth0
ip netns exec ns ip addr add 192.168.2.10/24 dev ceth1
ip netns exec ns ip link set ceth0 up
ip netns exec ns ip link set ceth1 up
!! 접속 후 ping Test
# ip netns exec ns ip addr show ceth0
84: ceth0@if83: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 96:2c:e4:36:ed:75 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.1.10/24 scope global ceth0
valid_lft forever preferred_lft forever
inet6 fe80::942c:e4ff:fe36:ed75/64 scope link
valid_lft forever preferred_lft forever
# ip netns exec ns ip addr show ceth1
86: ceth1@if85: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 46:4b:5b:f3:bd:fc brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.2.10/24 scope global ceth1
valid_lft forever preferred_lft forever
inet6 fe80::444b:5bff:fef3:bdfc/64 scope link
valid_lft forever preferred_lft forever
반응형
'Docker' 카테고리의 다른 글
[Docker] GPU 컨테이너 생성 (1) | 2024.10.23 |
---|---|
[Docker] Podman (3) | 2024.10.11 |
[Docker] 서로 다른 서버의 컨테이너 간 통신 (3) | 2024.10.01 |
[Docker] ceth, veth 각각 연결 vs 페어 연결 (0) | 2024.10.01 |
[Docker] Docker network 외부 통신하기(toy project) (0) | 2024.10.01 |