I have one container I would like to have a fixed IP.
My relevant setup (docker-compose) is the following:
version: '3'
networks:
default:
external:
name: srv
services:
caddy:
image: caddy
container_name: caddy
volumes:
- /etc/docker/data/caddy/Caddyfile:/etc/caddy/Caddyfile
- /etc/docker/data/caddy/data:/data
- /etc/docker/data/caddy/config:/config
ports:
- 80:80
- 443:443
- 2015:2015
environment:
- ACME_AGREE=true
restart: unless-stopped
# networks:
# srv:
# ipv4_address: 172.19.0.254
When the last lines are commented out, everything is fine. When I uncomment them, restarting the caddy
container yields the error
ERROR: Service "caddy" uses an undefined network "srv"
Inspecting the caddy
container when it runs correctly:
~ # docker inspect caddy
[
{
"Id": "37904d87c82c4612f48bcc9952b6505d871a816336c6b242b4ab3fae51cbfa95",
"Created": "2021-01-25T18:27:29.686179872Z",
"Path": "caddy",
(...)
"NetworkSettings": {
"Bridge": "",
"SandboxID": "1a4360ebfe25eff6dffec0f9ec049389da6e53e84eaf76db23bf6028868b31f3",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"2015/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "2015"
}
],
"2019/tcp": null,
"443/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "443"
}
],
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
]
},
"SandboxKey": "/var/run/docker/netns/1a4360ebfe25",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"srv": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"caddy",
"37904d87c82c"
],
"NetworkID": "36b7471fa0f16a74531b011ce6762cf66a802fda7622d70d66b6fb130a2398ea",
"EndpointID": "8dea6be732eda01a9b4d6cc0a26df2eca8a6df1a6f6d7a961fb46820a6ef9d58",
"Gateway": "172.19.0.1",
"IPAddress": "172.19.0.8",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:13:00:08",
"DriverOpts": null
}
}
}
}
]
How can I force that container to use a fixed IP?
Note: a similarly titled question (ERROR: Service "xxx" uses an undefined network "xxx") addresses the lack of a definition of the network (not my case)