Hello,
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 192.168.33.10/24 dev eth1
# Create "shared_nw" with a bridge name "docker1"
$ sudo docker network create \
--driver bridge \
--subnet=192.168.33.0/24 \
--gateway=192.168.33.10 \
--opt "com.docker.network.bridge.name"="docker1" \
shared_nw
# 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 192.168.33.11 -dt ubuntu
$ ping -c 3 192.168.33.11
For more detailed explanation, please visit my github repo.
https://github.com/kjtanaka/docker-example-shared-nw
If this approach has already widely been known, sorry…, please ignore this.