CNI and mac address

Bonjour, :wave:

Nomad version 1.7.7

Today I discovered CNI network and I tried to play with it.

Following this theard: How to configure CNI Macvlan in Nomad

My goal is to get static IP on my local network, I want my container can be reachable in LAN.

I tried many combinations to finally obtain this configuration:

{
  "cniVersion": "0.4.0",
  "name": "lan",
  "plugins": [
    {
      "type": "macvlan",
      "master": "eth0",
      "ipam": {
        "type": "static",
        "addresses": [
          {
            "address": "192.168.10.19/24",
            "gateway": "192.168.10.1"
          }
        ],
        "routes": [
          { "dst": "0.0.0.0/0" }
        ],
        "dns": {
          "nameservers" : ["192.168.10.1"]
        }
      }
    }
  ]
}

@rhessing, I don’t know if since 2021 you have found another solution.

But… I want something other.

Simply, I want to assign a mac address and can set static ip in my router for this mac address.
I don’t want a static configuration.

I create this CNI configuration with DHCP:

{
  "cniVersion": "0.4.0",
  "name": "local-arena-network",
  "plugins": [
    {
      "type": "macvlan",
      "master": "eth0",
      "ipam": {
        "type": "dhcp"
      }
    },
    {
      "type": "portmap",
      "capabilities": {
        "portMappings": true
      },
      "snat": true
    }
  ]
}

But, I can’t set mac address in job. This is part of my job:

job "jeedom.service.lan" {
  region = "global"
  datacenters = ["dc1"]
  type = "service"

  node_pool = "default"
  priority = 50
  all_at_once = false
  namespace = "default"

   update {
     max_parallel     = 1
     canary           = 1
     min_healthy_time = "10s"
     healthy_deadline = "5m"
     auto_revert      = true
     auto_promote     = true
     health_check     = "checks"
     stagger          = "30s"
   }

  group "jeedom" {

    count = 1

    restart {
      attempts = 10
      interval = "5m"
      delay = "10s"
      mode = "delay"
    }

    network {
      mode = "cni/local-arena-network"
    }

    task "jeedom" {
      driver = "docker"

      config {
        image = "jeedom/jeedom:latest"
        privileged = true
        
        mac_address = "02:68:b3:29:da:98"

        devices = [
          {
            host_path = "/dev/ttyUSB0"
            container_path = "/dev/ttyUSB0"
          }
        ]

        mount {
          type = "bind"
          target = "/var/www/html"
          source = "/data/jeedom.service.lan/data/var/www/html"
          readonly = false
          bind_options {
            propagation = "rshared"
          }
        }
        mount {
          type = "bind"
          target = "/var/lib/mysql"
          source = "/data/jeedom.service.lan/data/var/lib/mysql"
          readonly = false
          bind_options {
            propagation = "rshared"
          }
        }
      }

      template {
        data = <<EOH
ANSIBLE_FORCE_COLOR=TRUE

EOH
        destination = "secrets/file_group_01.env"
        env         = true
      }

      resources {
        cpu    = 2048
        memory = 2048
      }
    }
  }
}

Because when I launch job, I have this error:

**Driver Failure:** failed to create container: API error (400): conflicting options: mac-address and the network mode

Is it a limitation of docker drivers? Or I forget something in configuration to set mac_address?

I tried with the ipv4_address parameters but that doesn’t work either

Thanks for your help! :ring_buoy: