Hi I am new in docker network . Basically I want to start a docker container that should be mapped with existing HOST OS network interface .
For e.g. List of HOST OS network interfaces
$>>ip a
1. ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
4. ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
Now I want to create a Docker Network Bridge (mapped with ens192/ens224) using
$ docker network create -d bridge my-bridge-network
And then run the container using the docker network
$ docker run -itd --network=my-bridge-network mydocker
But with mentioned steps I am not able to map network interfaces with docker networks.
Assuming that you want your Docker container to display to the network as an ordinary device, you can "map" a host interface using a macvlan bridge. What you will get:
If that is not what you meant, please leave a comment and further explain your scenario.
Check weather macvlan module is installed using
lsmod | grep macvlan
If it is not listed, install it by issuing
modprobe macvlan
Create a network with the interface you want to share and specify subnet and gateway (gateway is optional if you want to use the internet via this network):
docker network create -d macvlan --subnet=1.2.3.4/24 --gateway=1.2.3.1 -o parent=eth0 nice_name
(parent must be changed from eth0 to your interface)
You can also create those networks on-demand and include them in your docker-compose.yml files like in the following example:
version: '3.3'
services:
nginx1:
restart: unless-stopped
image: nginx:latest
networks:
- nice_name
networks:
private:
nice_name:
driver: macvlan
driver_opts:
parent: eth0 # change this
ipam:
config:
- subnet: "1.2.3.0/24" # change this
gateway: "1.2.3.1" # change this (optional)
# Be aware that there is no "-" before "gateway" as it belongs to the subnet!
If you have already created the network outside of Docker-Compose, you can still connect clients to it that use Docker-Compose by using the external parameter:
version: '3.3'
services:
nginx1:
restart: unless-stopped
image: nginx:latest
networks:
- nice_name
networks:
nice_name:
external: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With