Docker Network Operations: Difference between revisions
Jump to navigation
Jump to search
Line 29: | Line 29: | ||
=Connect a Container to a Network= | =Connect a Container to a Network= | ||
==At Container Creation Phase== | |||
When a container is created with [[Docker create#Overview|docker create]], one more more --network flags can be specified. Docker will use this information to connect the container to the specified network(s). | When a container is created with [[Docker create#Overview|docker create]], one more more --network flags can be specified. Docker will use this information to connect the container to the specified network(s). | ||
Line 36: | Line 38: | ||
--publish <''host-port''>:<''container-port''> \ | --publish <''host-port''>:<''container-port''> \ | ||
... | ... | ||
==When the Container is Running== | |||
=Disconnect a Container from a Network= | =Disconnect a Container from a Network= | ||
docker network disconnect <''network-name''> <''container-name''> | docker network disconnect <''network-name''> <''container-name''> |
Revision as of 17:01, 30 April 2018
Internal
Overview
List Networks
docker network ls
Create a New User-Defined Bridge Network
Command creates a user-defined bridge network:
docker network create \ [--driver=bridge] \ [--subnet=172.29.0.0/16] \ [--ip-range=172.28.5.0/24 ] \ [--gateway=172.29.5.253] \ <user-defined-bridge-network-name>
Remove a User-Defined Bridge Network
docker network rm <user-defined-bridge-network-name>
Note that containers need to be disconnected first from the network being removed.
Connect a Container to a Network
At Container Creation Phase
When a container is created with docker create, one more more --network flags can be specified. Docker will use this information to connect the container to the specified network(s).
docker create --name <container-name> \ --network <network-name> \ --publish <host-port>:<container-port> \ ...
When the Container is Running
Disconnect a Container from a Network
docker network disconnect <network-name> <container-name>