맥북에서 도커 네트워크(brider)를 생성하는 예시이다.
$ docker network create --driver=bridge mynet
1e322c39b6415e3d6b76bee009e8282d6e9e738e9b35930abc875c1cf20578fa
$ docker network ls | grep mynet
1e322c39b641 mynet bridge local
정상적으로 드라이버가 생겼는지 확인한다.
$ ifconfig
(리눅스에서는 ip addr | grep br-)
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether 4a:00:24:80:b7:01
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en1 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 13 priority 0 path cost 0
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 14 priority 0 path cost 0
member: en3 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 15 priority 0 path cost 0
member: en4 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 16 priority 0 path cost 0
nd6 options=201<PERFORMNUD,DAD>
media: <unknown type>
status: inactive
생성된 네트워크(bridge)를 사용하는 컨테이너를 실행한다.
$ docker run -it -d --name container1 --net=mynet ubuntu:16.04 bash
두 번 커맨드를 사용해 생성된 네트워크(bridge)를 사용할 수 있다.
$ docker run -it -d --name container2 ubuntu:16.04 bash
$ docker network connect mynet container2
내부 ip를 확인해본다.
$ docker exec container1 ip addr
20: eth0@if21: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:19:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.25.0.2/16 brd 172.25.255.255 scope global eth0
valid_lft forever preferred_lft forever
$ docker exec container2 ip addr
(비슷하게 나온다)
'docker' 카테고리의 다른 글
[docker] Credentials store docker-credential-osxkeychain exited with "User interaction is not allowed." 해결하기 (0) | 2019.09.24 |
---|---|
[docker] docker-compose에서 특정 컨테이너(rabbitmq)만 실행하기 (0) | 2019.09.18 |
[docker] cmd와 entrypoint (0) | 2019.09.10 |
[docker] ENV와 ARG 비교 (0) | 2019.09.10 |
docker run 커맨드에 env 변수가 잘 동작하지 않는 이슈 해결하기 (0) | 2019.09.10 |