Docker network MacVLAN and IPvlan

edyuser12345

New Member
Joined
Feb 15, 2024
Messages
24
Reaction score
3
Credits
235
I have a question that I am not understanding about docker networks, Macvlan and ipvlan. In the first example, I want to show you the macvlan bridge mode network. This works correctly for me, I show you what I have done to make it work correctly.

1. First I have executed these commands

sudo ip link add macvlan_int link enp0s3 type macvlan mode bridge

sudo ip address add 192.168.1.2/24 dev macvlan_int

sudo ip link set macvlan_int up

sudo ip route add 192.168.1.110/32 dev macvlan_int

2. After I have run docker compose, I have it working this way.


Code:
version:'3.8'
service:
    profiles:
      - net7
    image: nginx
    networks:
     demo-macvlan:
      ipv4_address:  192.168.1.110
    stdin_open: true
    tty: true
    restart: 'no'
    init: true

networks:
  demo-macvlan:
    driver: macvlan
    ipam:
      config:
        - subnet: 192.168.1.0/24 
          gateway: 192.168.1.1 
    driver_opts:
      parent: enp1s0

3. I run this in my browser http://192.168.1.110 and the Macvlan Bridge mode works correctly

So far so good, it works well for me, but now the problems come. Before starting the next example I want to mention something to the previous example, if I have done something wrong or I want you to mention something to me, I am new to docker in networks. Now let's move on to the second example to the macvlan 802.1Q trunk bridge mode I want to implement this. The only thing I have done is the following in my docker compose.


Code:
version:'3.8'
service:
  ivlan2:
    profiles:
      - net8
    image: nginx
    networks:
      ip-vlan:
        ipv4_address: 192.168.1.130
    stdin_open: true
    tty: true
    restart: 'no'
    init: true

networks:
  net-app:
   external: true
  net:
    external: true
  demo-macvlan50-net:
    driver: macvlan
    ipam:
      config:
      - subnet:  192.168.1.0/24 
        gateway: 192.168.1.1
    driver_opts:
      parent: enp1s0.50
Here what I have done is the following, I have changed the IP to this 192.168.1.130 then I have added the enp1s0.50, ok so far everything is fine inside the container I execute the ping to the IP 192.168.1.130 and it works, it gives me a signal, but When I run this on my host and add the ping 192.168.1.130 it doesn't work correctly when I run that on my host and add the http://192.168.1.130 it tells me connection refused, I want to mention that I have no conflicts with anything I have checked it too I have run these commands netstat -rn | fgrep 0.0.0.0 || ip route, nmap -sn 192.168.1.0/24,ifconfig,netstat -a, ip -br -col add show to check if there is a problem, I can't solve the problem so that it works correctly, why do I get a signal that it works when pinging the IP address that I have assigned but on my host I do not receive a signal and it does not let me access the IP address from my host?

Now let's move on to the third example. I have a problem, I want to implement ipvlan l2 and the same thing happens to me as the second example. It doesn't work on the host of my system, but on the container it works when pinging the IP address.


Code:
version: '3.8'

services:
  ivlan2:
    profiles:
      - "net9"
    image: nginx
    networks:
      ip-vlan:
        ipv4_address: 192.168.1.110
    stdin_open: true
    tty: true
    restart: 'no'
    init: true

networks:
  ip-vlan: 
    driver: ipvlan
    ipam:
      config:
        - subnet: 192.168.1.0/24
          gateway: 192.168.1.1
    driver_opts:
      parent: enp1s0
      mode: l2
 
Last edited:


Latest posts

Top