title: How to create a Docker macvlan with user defined IP and MAC address using Compose
body: <p>I have a docker project that uses the MAC address for hardware license enforcement. I cannot change this, the ISV uses a hardware fingerprint that includes the MAC address.</p>
  
  <p>I am trying to create a macvlan network, that will use the physical adapter and get an IP address from my network DHCP server, alternatively I will assign a static IP address manually.
  I must be able to set the MAC address manually such that it does not dynamically change and invalidate my license key.</p>
  
  <p>Based on Docker docs the <code>mac_address</code> setting is deprecated, at least in v3 schema, but seems to be honored in v2 schemas.</p>
  
  <p>I have a config that builds, using vanilla LSIO Nginx as test, but fails to run with an error stating that the MAC address cannot be assigned.</p>
  
  <pre class="lang-yaml prettyprint-override"><code>version: "2.1"
  
  services:
    nginx:
      image: linuxserver/nginx
      container_name: nginx_macvlan
      environment:
        - TZ=Americas/Los_Angeles
      volumes:
        - .mount:/config
      ports:
        - 80:80
        - 443:443
      restart: unless-stopped
      mac_address: b7-48-d5-a6-d1-99
      networks: 
        nginx_vlan:
          ipv4_address: 192.168.1.10
  
  networks:
    nginx_vlan:
      driver: macvlan
      ipam:
        driver: default
        config:
          - subnet: 192.168.1.0/24
  </code></pre>
  
  <pre><code>PS C:\Users\piete\source\TestMacVlan&gt; cd "c:\Users\piete\source\TestMacVlan"
  PS C:\Users\piete\source\TestMacVlan&gt; docker-compose -f "docker-compose-macvlan.yml" up -d --build
  Creating network "testmacvlan_nginx_vlan" with driver "macvlan"
  Creating nginx_macvlan ... error
  
  ERROR: for nginx_macvlan  Cannot start service nginx: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"process_linux.go:432: running prestart hook 0 caused \\\"error running hook: exit status 1, stdout: , stderr: time=\\\\\\\"2020-05-16T02:46:50Z\\\\\\\" level=fatal msg=\\\\\\\"failed to add interface veth2b7c9ef to sandbox: error setting interface \\\\\\\\\\\\\\\"veth2b7c9ef\\\\\\\\\\\\\\\" MAC to \\\\\\\\\\\\\\\"b7:48:d5:a6:d1:99\\\\\\\\\\\\\\\": cannot assign requested address\\\\\\\"\\\\n\\\"\"": unknown
  
  ERROR: for nginx  Cannot start service nginx: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"process_linux.go:432: running prestart hook 0 caused \\\"error running hook: exit status 1, stdout: , stderr: time=\\\\\\\"2020-05-16T02:46:50Z\\\\\\\" level=fatal msg=\\\\\\\"failed to add interface veth2b7c9ef to sandbox: error setting interface \\\\\\\\\\\\\\\"veth2b7c9ef\\\\\\\\\\\\\\\" MAC to \\\\\\\\\\\\\\\"b7:48:d5:a6:d1:99\\\\\\\\\\\\\\\": cannot assign requested address\\\\\\\"\\\\n\\\"\"": unknown
  ERROR: Encountered errors while bringing up the project.
  PS C:\Users\piete\source\TestMacVlan&gt; 
  </code></pre>
  
  <p>I am testing on Win10 using Docker for Windows.</p>
  
  <pre class="lang-bsh prettyprint-override"><code>PS C:\Users\piete\source\TestMacVlan&gt; docker --version
  Docker version 19.03.1, build 5b38d82a-
  
  PS C:\Users\piete\source\TestMacVlan&gt; [Environment]::OSVersion               
  
  Platform ServicePack Version      VersionString
  -------- ----------- -------      -------------
   Win32NT             10.0.18363.0 Microsoft Windows NT 10.0.18363.0
  </code></pre>
  
  <p>How do I use macvlan in compose and set a MAC and IP or use DHCP for IP?</p>