Docker Community Forums

Share and learn in the Docker community.

Having containers on a shared network

(Koji Tanaka) #1


I figured out how to create containers on a shared network among my MacBook, VMs, and containers in a simple way, without using an additional tool.

I know the pipework works great, but here’s another option you may want to try. The follows is an example of making a bridge on eth1. (* Before trying it, please make sure you log in to the machine via another network interface such as eth0 because you need to once delete the IP address from eth1.)

# Delete the IP address from eth1
$ sudo ip addr del dev eth1

# Create "shared_nw" with a bridge name "docker1"
$ sudo docker network create \
    --driver bridge \
    --subnet= \
    --gateway= \
    --opt ""="docker1" \

# Add docker1 to eth1
$ sudo brctl addif docker1 eth1

After making the bridge, you should be able to create a container from your MacBook, and you can reach the container’s IP address like this.

$ eval $(docker-machine env <your_env>) # Setup the environment
$ docker run --name container1 --net shared_nw --ip -dt ubuntu
$ ping -c 3

For more detailed explanation, please visit my github repo.

If this approach has already widely been known, sorry…, please ignore this.