Docker

Docker network 생성 / container IP 확인

thxxyj 2022. 10. 1. 23:17
728x90

Docker network 조회

user@server01:~$ docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
635c61a5e6fe   bridge    bridge    local
f343598b37e2   host      host      local
1210dce73ff5   none      null      local

bridge, host, none은 Docker daemon이 실행되면서 기본 생성되는 네트워크

 

Docker network 종류

  • bridge: 하나의 호스트 내에서 여러 컨테이너 간 네트워킹
  • host: 호스트와 동일한 네트워크에서 컨테이너를 사용
  • overlay: 여러 호스트의 컨테이너들 간 네트워킹을 위해서 사용

 

Docker network 생성

https://docs.docker.com/engine/reference/commandline/network_create/

tfsmaster@tw-tfs-master:~$ docker network create --driver=bridge --subnet=172.28.0.0/24 my-net
2096797668b24a16034bb34cd3259176fe24aa616103f6481e91c84e2f752486
# driver 옵션이 없으면 default로 bridge로 지정됨

tfsmaster@tw-tfs-master:~$ docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
635c61a5e6fe   bridge    bridge    local
f343598b37e2   host      host      local
2096797668b2   my-net    bridge    local
1210dce73ff5   none      null      local

 

 


Container IP 확인

컨테이너 전체 정보 확인: docker inspect ${CONTAINER_ID}

각 컨테이너의 내부 ip 확인: docker inspect ${network_name}

 

# docker inspect my-net
	"Containers": { 
		"27a420168e40c.....": { 
			"Name": "container_id1",
			"EndpointID":"2c15255254a.......",
			"MacAddress": "02:42:ac:12:00:04",
			"IPv4Address": "172.28.0.104/24",	# 컨테이너 ip
			"IPv6Address": ""
		},
	   "5425326608ac.......": {
			"Name": "container_id2",
			"EndpointID": "fbbbf9c37......",
			"MacAddress": "02:42:ac:12:00:02",
			"IPv4Address": "172.28.0.102/24",	# 컨테이너 ip
			"IPv6Address": ""
		},
		"b1b9647a1edb8........": {
			"Name": "container_id3",
			"EndpointID": "02e902d.........",
			"MacAddress": "02:42:ac:12:00:03", 
		    "IPv4Address": "172.28.0.103/24",	# 컨테이너 ip
			"IPv6Address": ""
		}
	}
728x90