This is my first post so: Hello :)
I want to have a container connected to two docker networks on the same host. I want to have static IP's for each network. Networks are already created. I was able to set a static IP with one network
version: '3.3'
services:
homer:
ports:
- '7070:8080'
volumes:
- '/docker/homertest:/www/assets'
restart: always
hostname: homer-test
networks:
#default
#ipv4_address: 172.19.0.222
frontend:
ipv4_address: 172.18.0.111
# - kuma:
# ipv4_address: 172.20.0.222
#- smtp
container_name: homer
image: 'b4bz/homer:latest'
networks:
default:
external:
name: nginx-proxy-manager_default
frontend:
external:
name: portainer_default
kuma:
external:
name: uptime-kuma_default
smtp:
external:
name: smtp-relay_default
but with two or more
version: '3.3'
services:
homer:
ports:
- '7070:8080'
volumes:
- '/docker/homertest:/www/assets'
restart: always
hostname: homer-test
networks:
#default
#ipv4_address: 172.19.0.222
- frontend:
ipv4_address: 172.18.0.111
- kuma:
ipv4_address: 172.20.0.222
#- smtp
container_name: homer
image: 'b4bz/homer:latest'
networks:
default:
external:
name: nginx-proxy-manager_default
frontend:
external:
name: portainer_default
kuma:
external:
name: uptime-kuma_default
smtp:
external:
name: smtp-relay_default
I get an error
services.homer.networks contains {"frontend": {"ipv4_address": "172.18.0.111"}}, which is an invalid type, it should be a string
What am I doing wrong?
CodePudding user response:
You are using a mapping in the first version, but in the second one you are using a list. Keep it a mapping.
networks:
frontend:
ipv4_address: 172.18.0.111
kuma:
ipv4_address: 172.20.0.222
You can also review the json schema for compose files.
What do I mean by list and mapping?
list:
- a
- b
mapping:
a:
b:
This would translate to json in like the below, which may make it more clear:
{
"list": [
"a",
"b"
],
"mapping": {
"a": null,
"b": null
}
}
CodePudding user response:
Simply remove the hyphens used in front of frontend and kuma. This will make it mapping from list and it will work.