Docker Community Forums

Share and learn in the Docker community.

A little network fundamentals share

docker

(Brilliance643) #1

why? - because i was using community materials for ages but have not brought anything to it yet.

  1. Docker creates bridge network by default like “docker0” and your container will be accessable through the LAN (using your host IP address) if you exposed some port.

  2. I faced with one simple requirement to attach another IP address to docker container, i watched plenty of videos and tutorials which costed me lots of time and purging docker.io and i still was not able to meet that requirement, drivers like MACVLAN and etc either has not been recognized in proper way by a system and something like that so i decided to go aside of docker tools, simple steps:

/etc/network/interfaces (add-create sub interface)
auto enp0s31f67:1
iface enp0s31f67:1 inet static
address 10.10.10.18 #desired IP
netmask 255.255.255.0
restart the network

docker network create \
-o “com.docker.network.bridge.host_binding_ipv4”=“10.10.10.18” \
customnetwork
#Will create network with default behavior (bridge)

And, finally, attach some container to your “customnetwork” while starting container:
docker run \
-d \
–name container \
-p 80:80 \
–net customnetwork \
container/repository

After those simple steps you WILL be able to reach your container from any workstation in your LAN and from your host as well, please note, ip address 10.10.10.18 shoud be aside of dhcp pool of your router.