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.
Lifecycle
docker network create
NAME Create a new network (default type: bridge).docker network rm
NAME Remove one or more networks by name or identifier. No containers can be connected to the network when deleting it.
Info
docker network ls
List networksdocker network inspect
NAME Display detailed information on one or more networks.
Connection
docker network connect
NETWORK CONTAINER Connect a container to a networkdocker network disconnect
NETWORK CONTAINER Disconnect a container from a network
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