portainer: mac_address is being ignored in docker-compose files

Before you start please confirm the following.

Problem Description

This is the docker-compose used for setting the mac_address line. This used to work fine until recently. If I run this outside of Portainer with docker-compose up it generates the MAC address fine.

I am not using a swarm, which another user was having an issue with the same problem: https://github.com/portainer/portainer/issues/9152

Does this have to do with the issue? https://github.com/moby/moby/pull/46406

# Wyoming-OpenWakeWord Container for Docker
version: "3.9"
services:
  wyomingopenwakeword:
    container_name: "wyoming-openwakeword"
    image: "rhasspy/wyoming-openwakeword:latest"
    labels:
      - "com.centurylinklabs.watchtower.enable=true"
      - "com.centurylinklabs.watchtower.monitor-only=false"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/lib/libvirt/images/usb001/docker-storage/wyoming-openwakeword/data:/data
    mac_address: "9e:de:ad:be:ef:01"
    hostname: "wyomingopenwakeword"
    networks:
      - dhcp
    ports:
      - 10400:10400
    devices:
      - /dev/snd:/dev/snd
    command: --model 'ok_nabu' --model 'hey_jarvis' --model 'hey_rhasspy' --model 'hey_mycroft' --model 'alexa' --preload-model 'ok_nabu'    
    # --uri 'tcp://0.0.0.0:10400'
    restart: "no"
    #restart: unless-stopped
    #privileged: true
    #network_mode: host

networks:
  dhcp:
    name: "dbrv100"
    external: true
Network IP Address Gateway MAC Address Actions
dbrv100 10.0.10.100 10.0.10.1 16:a7:42:02:66:94 Leave network

Random generated MAC ================^

I use static set IP addresses by MAC dished out from DNSMasq DHCP so this breaks all the services for me as they just get random IP addresses instead of their statically defined ones.

Expected Behavior

Generate the mac_address specified.

Actual Behavior

Generates random MAC address.

Steps to Reproduce

Add a new stack, name your stack, dump the yaml above in the web editor, deploy the stack.

Portainer logs or screenshots

Client: Version: 24.0.5 API version: 1.43 Go version: go1.20.6 Git commit: ced0996600 Built: Wed Jul 26 21:44:58 2023 OS/Arch: linux/amd64 Context: default

Server: Engine: Version: 24.0.5 API version: 1.43 (minimum version 1.12) Go version: go1.20.6 Git commit: a61e2b4c9c Built: Wed Jul 26 21:44:58 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.7.6 GitCommit: 091922f03c2762540fd057fba91260237ff86acb.m runc: Version: 1.1.9 GitCommit: docker-init: Version: 0.19.0 GitCommit: de40ad0

Portainer version

2.19.1

Portainer Edition

Community Edition (CE)

Platform and Version

Docker 24.0.5 | docker-compose 2.20.3

OS and Architecture

Arch Linux 6.5.5-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 23 Sep 2023 22:55:13 +0000 x86_64 GNU/Linux

Browser

Chrome Version 117.0.5938.92 (Official Build) (64-bit)

What command did you use to deploy Portainer?

Pushed the "Deploy the stack" button on the WebUI.

Additional Information

I noticed the version of compose the containers say they used seem to be perpetually set to when they were first deployed:

com.docker.compose.version | 2.20.2

Maybe this is just a database entry as when you hit redeploy it doesn’t update that field. As I have 2.20.3 of compose installed or does Portainer have it’s own docker-compose resource i.e. not /usr/bin/docker-compose etc?

I believe docker-compose had an issue https://github.com/moby/moby/pull/46406 with setting mac_address in this version. It said it was fixed 3 weeks ago maybe that is something? Does docker-compose need to be updated in Portainer to take advantage of this fix or it should use the system /usr/bin/docker-compose etc?

Thank you.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 5
  • Comments: 55

Commits related to this issue

Most upvoted comments

I had this issue in a different context. I found the following and it led to the solution of my problem.

Note Container runtimes might reject this value (ie. Docker Engine >= v25.0). In that case, you should use networks.mac_address instead.

See here.

So I switched from

version: '3.8' # Example version
services:
  your_service:
    image: your_image
    mac_address: your_mac_address

to

version: '3.8' # Example version
services:
  your_service:
    image: your_image
    networks:
      default:
        mac_address: your_mac_address

Now, the mac address is correctly set in my container.

I tested this and it’s an issue with an older version of Docker Compose, an updated version will be included in the 2.20 release which will resolve this issue.

Just so you know, I see you use Watchtower there… which doesn’t support the new mac_address under networks yet and since their repo has gone pretty dormant not sure if we will expect a fix for it.

If you use watchtower https://github.com/portainer/portainer/issues/10393#issuecomment-1974914428 just for notifications it won’t affect you, but if you use it to pull docker images… every time it does your docker will lose the mac address. If you then repull it with portainer it will fix it again.

I have a ticket with them as well for this issue. https://github.com/containrrr/watchtower/issues/1941

@Nick-Portainer Was this supposed to be fixed in 2.21.0 that was released? Because my server docker compose respects the MAC address i specify in compose file, but 2.21.0 portainer does not still.

Still happening:

Server Version: 2.19.4	
Database Version: 2.19.4
CI Build Number: 35427	
Image Tag: linux-amd64-2.19.4

Compilation tools:
Nodejs v18.19.0
Yarn v1.22.21
Webpack v5.88.1
Go v1.20.5

I am also seeing the same issue. I ended up rolling back to 2.17.1 to restore functionality. Seems it was introduced with 2.18.0

Rather run latest patches/versions. Please advice on an eta for the fix.

Sample compose doc. Seeing the issue across all of them:

`
version: "3"
services:
  watchtower:
    image: containrrr/watchtower:latest
    container_name: watchtower-vm
    mac_address: da:de:40:30:22:ae
    environment:
      - WATCHTOWER_SCHEDULE=0 0 4 * * *
      - WATCHTOWER_CLEANUP=true
      - WATCHTOWER_INCLUDE_RESTARTING=true
      - WATCHTOWER_INCLUDE_STOPPED=true
      - WATCHTOWER_DEBUG=false
      - TZ=America/Phoenix
      - DOCKER_CONFIG=/config
    restart: unless-stopped

    networks: 
      - eth3

    volumes:
      - type: bind
        source: /var/run/docker.sock
        target: /var/run/docker.sock
      - config-data:/config/

volumes:
  config-data:
    name: docker-config
    external: true    

networks:
  eth3:
    name: qnet-dhcp-eth3-6d6da6
    external: true

`

Testing Successful

  • Updated from ce:2.17.1 (last version that supported old schema) to Community Edition 2.21.5. (portainer/portainer-ce:latest)
  • Updated all Custom Templates per docker documentation.
  • Relaunched all stacks
  • Verified in Portainer and pfSense IP/Hostname assignment still successful.

Example Update:

services:
  watchtower:
    image: containrrr/watchtower:latest
    container_name: watchtower-vm
    hostname: watchtower-vm
    dns:
      - 192.168.0.1
    environment:
      - DOCKER_CONFIG:/config 
      - WATCHTOWER_SCHEDULE=0 0 4 * * *
      - WATCHTOWER_CLEANUP=true
      - WATCHTOWER_INCLUDE_RESTARTING=true
      - WATCHTOWER_INCLUDE_STOPPED=true
      - WATCHTOWER_DEBUG=false
      - WATCHTOWER_NOTIFICATIONS=email
      - WATCHTOWER_NOTIFICATION_EMAIL_FROM=xxxxxx@xxxxxxx.org
      - WATCHTOWER_NOTIFICATION_EMAIL_TO=xxxx@xxxxxxxxx.org
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp-vm.xxxxxxxx.org
      - WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT=25
      - WATCHTOWER_NOTIFICATION_EMAIL_DELAY=2
      - TZ=America/Phoenix
    restart: unless-stopped
    networks: 
      eth3:
        mac_address: da:de:40:30:22:ae
    volumes:
      - json-config:/config
      - type: bind
        source: /var/run/docker.sock
        target: /var/run/docker.sock
        
volumes:
  json-config:
    name: docker-config 
    external: true

networks:
  eth3:
    name: qnet-dhcp-eth3-6d6da6
    external: true

Looks promising, let me update and test against the latest.

Thanks, Bill B.

On Fri, Dec 20, 2024 at 9:12 PM NonaSuomy @.***> wrote:

You have the mac_address under the wrong section in the YAML please review my comment here #10393 (comment) https://github.com/portainer/portainer/issues/10393#issuecomment-1969913759

— Reply to this email directly, view it on GitHub https://github.com/portainer/portainer/issues/10393#issuecomment-2557987471, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACC33KNRHJJJL7PPPSUNYUT2GTTEDAVCNFSM6AAAAAA5LDVPQSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNJXHE4DONBXGE . You are receiving this because you were mentioned.Message ID: @.***>

@Nick-Portainer is this still being looked at or is it a lost cause? If it’s not going to be fixed, I’ll move away from using portainer as it’s a deal breaker for my environment.

Any updates on the 2.21 release @Nick-Portainer ? I’ve been unable to re-deploy any macvlan stacks still since I’m waiting on the longer term support.

Within July at this stage

Cool I’ll keep tracking this issue, I’m eager to be able to use my YAML and stacks inside portainer again, instead of the “glass break” solution of going out of portainer.

Is there an estimated release date* for 2.20 @Nick-Portainer ?

No offical date I can provide, but the team is very close 😃

Great, thanks for testing that and providing feedback that it’s now working. Please remember 2.20 is not currently released and the version I provided is just for testing 😃

Figured out the syntax I had was just wrong should have been like this for version 25:

version: '3.8'
services:
  nginx:
    image: nginx:latest
    networks:
      dhcp:
        mac_address: de:ad:be:ef:00:01
networks:
  dhcp:
    name: dbrv100
    external: true

Looks like it is working now yay!

            "Networks": {
                "dbrv100": {
                    "IPAMConfig": {},
                    "Links": null,
                    "Aliases": [
                        "mactest-nginx-1",
                        "nginx",
                        "############"
                    ],
                    "MacAddress": "de:ad:be:ef:00:01",
                    "NetworkID": "0b...",
                    "EndpointID": "75...",
                    "Gateway": "10.0.42.1",
                    "IPAddress": "10.0.42.121",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "DriverOpts": null,
                    "DNSNames": [
                        "mactest-nginx-1",
                        "nginx",
                        "############"
                    ]
                }
            }

Are you able to point to the fix in github I can’t seem to find it. Can I manually build it in some way?

Hey, so you can try our dev image of 2.20 please keep in mind this it not live and is not suitable for production and should only be used for testing, please let me know how this goes for you.

Business Edition https://hub.docker.com/r/portainerci/portainer-ee/tags portainerci/portainer-ee:2.20 Community Edition https://hub.docker.com/r/portainerci/portainer/tags docker pull portainerci/portainer:2.20

Is there an ETA on the 2.20 release?

I can’t give dates but we are now in code freeze, so it’s close 😃

I tested this and it’s an issue with an older version of Docker Compose, an updated version will be included in the 2.20 release which will resolve this issue.

I’m eager to see the fix and try again in-place. Thank you for helping me escalate this issue.

Thanks for raising this, I am going to follow this up internally and test this. I will give updates here