Skip to content

Latest commit

 

History

History
16 lines (11 loc) · 1.16 KB

commands_network.md

File metadata and controls

16 lines (11 loc) · 1.16 KB

Network commands

Docker has a networks feature. Docker automatically creates 3 network interfaces when you install it (bridge, host, none). A new container is launched into the bridge network by default. To enable communication between multiple containers, you can create a new network and launch containers in it. This enables containers to communicate to each other while being isolated from containers that are not connected to the network. Furthermore, it allows to map container names to their IP addresses. See working with networks for more details.

You can specify a specific IP address for a container:

# create a new bridge network with your subnet and gateway for your ip block
docker network create --subnet 203.0.113.0/24 --gateway 203.0.113.254 iptastic

# run a nginx container with a specific ip in that block
$ docker run --rm -it --net iptastic --ip 203.0.113.2 nginx

# curl the ip from any other place (assuming this is a public ip block duh)
$ curl 203.0.113.2