- docker network ls
docker network ls
NETWORK ID NAME DRIVER SCOPE
290558d808c0 bridge bridge local
3ee744dfe053 host host local
b9d8dd48b0e2 none null local
Representative network drivers which can be connected external are bridge, host, none, container.
1. bridge : It already setup to utilize docker0, it(bridge network) allocates 172.17.0.x in order to container. It is user defined network, so it needs to be created.
- docker network inspect bridge
docker network inspect bridge
[
{
"Name": "bridge",
...
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
...
- docker network create --driver bridge mybridge
Let's create new network bridge driver.
docker network create --driver bridge mybridge
c65049fd0e78b8f6250e06fa559cbf3a9e4f340d70169c4436a8856a5dcb625d
--driver : Bridge Driver, create
- docker run -i -t --name mynetwork_container --net mybridge ubuntu:14.04
Let's setup to use mybridge network after generate container.
Internal IP(inet addr:172.18.0.2) has been allocated.
docker run -i -t --name mynetwork_container --net mybridge ubuntu:14.04
...
root@3c532989089b:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:ac:12:00:02
inet addr:172.18.0.2 Bcast:172.18.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1312 (1.3 KB) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
--net : Network, create network
- docker network disconnect mybridge mynetwork_container
Let's disconnect bridge network(mybridge) from container(mynetwork_container).
- docker network connect mybridge mynetwork_container
Let'sconnect bridge network(mybridge) to container(mynetwork_container).
2. host : It can be used host network when network is setup as host.
- docker run -i -t --name network_host --net host ubuntu:14.04
If you use the host network mode for a container, the container does not get its own IP-address allocated. For instance, if you run a container which binds to port 80 and you use host networking, the container's application is available on port 80 on the host's IP addre
docker run -i -t --name network_host --net host ubuntu:14.04
root@docker-desktop:/# echo "inside the container"
inside the container
root@docker-desktop:/# ifconfig
br-c65049fd0e78 Link encap:Ethernet HWaddr 02:42:cc:74:03:07
inet addr:172.18.0.1 Bcast:172.18.255.255 Mask:255.255.0.0
inet6 addr: fe80::42:ccff:fe74:307/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:626 (626.0 B)
docker0 Link encap:Ethernet HWaddr 02:42:da:64:36:c3
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth0 Link encap:Ethernet HWaddr 02:50:00:00:00:01
inet addr:192.168.65.3 Bcast:192.168.65.255 Mask:255.255.255.0
inet6 addr: fe80::50:ff:fe00:1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4593 errors:0 dropped:0 overruns:0 frame:0
TX packets:4608 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:423774 (423.7 KB) TX bytes:372824 (372.8 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:52 errors:0 dropped:0 overruns:0 frame:0
TX packets:52 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4392 (4.3 KB) TX bytes:4392 (4.3 KB)
vethb2fdb53 Link encap:Ethernet HWaddr ce:13:e2:22:77:38
inet6 addr: fe80::cc13:e2ff:fe22:7738/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:1116 (1.1 KB)
3. none : I don't want to use any network. It cuts off from external.
- docker run -i -t --name network_none --net none ubuntu:14.04
Notice that no eth0 was created.
docker run -i -t --name network_none --net none ubuntu:14.04
root@dc8ca116692c:/# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
'Docker' 카테고리의 다른 글
Install the docker-compose (0) | 2021.04.12 |
---|---|
MAC address, VLAN, LAN, -d, --driver, --subnet, --ip-range, -o, (0) | 2021.02.23 |
--net, HWaddr, --net-alias, grep, -c, round-robbin, dig (0) | 2021.02.22 |
-d, -e, -v, --link, inspect, --type, volume, prune (0) | 2021.02.22 |
docker, linuxkit, virtualbox, instance, volume, snapshots, EC2, tty (0) | 2021.02.09 |