Create a Network and Attach a Container
A 5-step recipe with Docker. We can help you get access.
Recipe · 5 steps
Create a Network and Attach a Container
with Docker
Create a user-defined network and attach a new container to it under an alias.
- Create the user-defined network. Unlike the default bridge, a user-defined network gives attached containers automatic DNS resolution of each other by name and alias.
- Create the container that will join the network. It is created but not yet started, so the network attachment can be made before the workload comes up.
- Attach the container to the network under a DNS alias, so peers can resolve it by that alias rather than by container name alone.
- Start the container now that it is attached, so it comes up already resolvable on the network.
- Inspect the network in verbose mode to confirm the container appears in its attached container list with an allocated IP address.
What you'll need to have ready
- networkName: Name of the user-defined network to create (e.g. "app_net").
- driver: Network driver to use — "bridge" for single host, "overlay" for swarm.
- image: Image to create the container from. It must already be present locally.
- containerName: Name to assign to the created container.
- networkAlias: DNS alias other containers on the network will use to reach this one.
- internal: Restrict external access to the network.
For your developer
Arazzo workflow docker:provision-network-and-attach, 5 operations: NetworkCreate → ContainerCreate → NetworkConnect → ContainerStart → NetworkInspect. Specs on APIs.io.