Docker는 기본적으로 컨테이너의 네트워크 네임스페이스를 호스트의 runtime data에 추가하지 않는다 (/run의 tmpfs로 마운트 되는 /var/run을 의미함)

실행된 컨테이너의 pid로 심볼릭 링크를 만들어주면 컨테이너의 네트워크 네임스페이스를 확인 할 수 있다.

# 호스트 네트워크
root@docker1:~# ip -br -c a
lo               UNKNOWN        127.0.0.1/8 ::1/128
enp0s3           UP             10.0.2.15/24 fe80::31:14ff:fe45:3203/64
enp0s8           UP             192.168.50.10/24 fe80::a00:27ff:fe7c:22c3/64
docker0          UP             172.17.0.1/16 fe80::42:23ff:fef8:ad75/64
vethca6cbca@if7  UP             fe80::e07c:f6ff:fe2c:6d25/64

root@docker1:~# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS         PORTS     NAMES
71118483fd2e   ubuntu    "bash"    9 minutes ago   Up 9 minutes             sharp_panini
root@docker1:~# ip netns list  # 컨테이너가 실행 중인데 네트워크 네임스페이스가 조회되지 않는다.
root@docker1:~# pid="$(docker inspect -f '{{.State.Pid}}' "711184" )"
root@docker1:~# echo $pid
8719
root@docker1:~# ls -l /var/run/netns
total 0
root@docker1:~# ln -s /proc/$pid/ns/net /var/run/netns/ubuntu
root@docker1:~# ip netns list
ubuntu (id: 0)
root@docker1:~# ip netns exec ubuntu ip -br -c a
lo               UNKNOWN        127.0.0.1/8
eth0@if8         UP             172.17.0.2/16
root@docker1:~#

 

참고

https://platform9.com/blog/container-namespaces-deep-dive-container-networking/

ubuntu 컨테이너 이미지에 ip 명령이 없을 때, apt source를 추가해주고 iproute2를 설치하면 된다.

iproute2 외 nettools 패키지도 네트워크 관련 좋은 도구가 많다.

 

root@71118483fd2e:/# ip -br -c a
bash: ip: command not found
root@71118483fd2e:/# apt install iproute2
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package iproute2
root@71118483fd2e:/# sed -i 's/archive.ubuntu.com/ftp.daum.net/g' /etc/apt/sources.list
root@71118483fd2e:/# apt update && apt -y install iproute2
Get:1 http://mirror.kakao.com/ubuntu focal InRelease [265 kB]
Get:2 http://mirror.kakao.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://mirror.kakao.com/ubuntu focal-backports InRelease [108 kB]
Get:4 http://mirror.kakao.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [837 kB]
Get:7 http://mirror.kakao.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:8 http://mirror.kakao.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:9 http://mirror.kakao.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:10 http://mirror.kakao.com/ubuntu focal-updates/universe amd64 Packages [1118 kB]
Get:11 http://mirror.kakao.com/ubuntu focal-updates/main amd64 Packages [1844 kB]
Get:12 http://mirror.kakao.com/ubuntu focal-updates/multiverse amd64 Packages [33.7 kB]
Get:13 http://mirror.kakao.com/ubuntu focal-updates/restricted amd64 Packages [899 kB]
Get:14 http://mirror.kakao.com/ubuntu focal-backports/universe amd64 Packages [22.4 kB]
Get:15 http://mirror.kakao.com/ubuntu focal-backports/main amd64 Packages [50.8 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1417 kB]
Get:17 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [30.1 kB]
Get:18 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [833 kB]
Fetched 20.5 MB in 10s (2000 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree
Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up iproute2 (5.5.0-1ubuntu1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
root@71118483fd2e:/# ip -br -c a
lo               UNKNOWN        127.0.0.1/8
eth0@if8         UP             172.17.0.2/16

+ Recent posts