I’ve been chasing this issue for months now. Various solution are claimed to work.
Background: Docker on Synology with DSM7.1.
bash-4.4# docker version
Client:
Version: 20.10.3
API version: 1.41
Go version: go1.17.1
Git commit: 55f0773
Built: Wed Feb 9 04:04:10 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.3
API version: 1.41 (minimum version 1.12)
Go version: go1.17.1
Git commit: b487c8f
Built: Wed Feb 9 04:04:31 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.4.3
GitCommit: 3fa00912415f3e9c6f82dd72119179d599efd13b
runc:
Version: v1.0.0-rc93
GitCommit: 31cc25f16f5eba4d0f53e35374532873744f4b31
docker-init:
Version: 0.19.0
GitCommit: ed96d00
bash-4.4# docker-compose version
docker-compose version 1.28.5, build 24fb474e
docker-py version: 4.4.4
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
Running portainer, version 2.11.
I have a macvlan with the top a.b.c.128/25 addresses available. I have two containers I run: one with sonos-samba, and one (migrating to) gitea. If I reboot the NAS, the IP address assignment depends on the startup order of the containers, resulting in the wrong IP address being assigned. sonos-samba requires a fixed IP on my LAN because the sonos APP needs it to find the music library. gitea needs a fixed IP address because all my git remote paths have the embedded IP address. Also, the address is embedded in the config file.
Much googling results in many folks having similar requirements. Many “claim” to have a solution. One was that supposedly in Portainer you can “redeploy/edit” the contained and go down to the network area and specify an address. Slam-dunk, that issue was closed as “solved” so I tried that. The IP address assignment did not stick anywhere. Did not take effect. Subsequent “redeploy/edit” shows it does not save the edited IP address value.
Many supposed solutions (as in this thread) suggest that docker-compose can be used, so I have been trying that lately. So far, no suck luck. I have explicitly moved the gitea address from .129 (which is after the .128 the sonos-samba is on) to .131 to test this. Despite my docker-compose attempts, it ignores the IP address setting.
version: "3.4"
services:
server:
image: gitea/gitea:latest
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
- TZ=AEST
restart: always
networks:
macvlan3:
ipv4_address: 192.168.3.131
volumes:
- '/volume1/docker/gitea/data:/data'
- '/etc/localtime:/etc/localtime:ro'
ports:
- "3000:3000"
- "22:22"
cap_add:
- NET_ADMIN
extra_hosts:
- "gitea.zepherin.com:192.168.3.131"
networks:
macvlan3:
external:
name: macvlan3
This corresponds to the “this works for me” comment above.
This does not work for me. I just started my gitea container. The sonos-samba one was already running.
bash-4.4# docker network inspect sglt
[
{
"Name": "macvlan3",
"Id": "sgltu774wevay1kv15m4p8a7f",
"Created": "2022-04-25T16:25:42.409407246+10:00",
"Scope": "swarm",
"Driver": "macvlan",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "192.168.3.0/24",
"IPRange": "192.168.3.128/25",
"Gateway": "192.168.3.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": "macvlan3.config"
},
"ConfigOnly": false,
"Containers": {
"b0a59d372aa4c981401c1c9d4bd0603b5774e7100603e28ac7c473b8adeb5040": {
"Name": "gitea",
"EndpointID": "7f3faad12292904be4cebbd0bea904fba7121a2e3f0d1900082206865072135b",
"MacAddress": "02:42:c0:a8:03:81",
"IPv4Address": "192.168.3.129/24",
"IPv6Address": ""
},
"da8d8b8f8e8664c80aaea11bb4de47c7608319e92f42cbd2daf17ec9657899f7": {
"Name": "00-sonos-samba",
"EndpointID": "6cc67f500706d53869d0fa278f4613d41b6996df330fcc7b969b65b797eec847",
"MacAddress": "02:42:c0:a8:03:80",
"IPv4Address": "192.168.3.128/24",
"IPv6Address": ""
}
},
"Options": {
"parent": "eth0"
},
"Labels": {},
"Peers": [
{
"Name": "cd5419e93e80",
"IP": "192.168.3.33"
}
]
}
]
Here are the network settings from docker inspect gitea
as currently running:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "409dbfab01f4c385d0e4744e104c67fa95013349f4c390b23ca2241d2be029e4",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/409dbfab01f4",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"macvlan3": {
"IPAMConfig": {},
"Links": null,
"Aliases": [
"b0a59d372aa4",
"server"
],
"NetworkID": "sgltu774wevay1kv15m4p8a7f",
"EndpointID": "7f3faad12292904be4cebbd0bea904fba7121a2e3f0d1900082206865072135b",
"Gateway": "192.168.3.1",
"IPAddress": "192.168.3.129",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:c0:a8:03:81",
"DriverOpts": null
}
}
}
I have put an explicit ifconfig
in the gitea container which seems to do the trick for now, but I would prefer to find a solution which actually works for the next service i might want to deploy on the macvlan.