Merge pull request #10246 from zhangguanzhang/compose-static-ip

Fixes docker-compose cannot set static ip when use ipam
This commit is contained in:
OpenShift Merge Robot 2021-05-06 09:16:04 -04:00 committed by GitHub
commit d6000a0b86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View file

@ -302,6 +302,11 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup
staticIP := net.ParseIP(ep.IPAddress)
netInfo.StaticIP = &staticIP
}
// if IPAMConfig.IPv4Address is provided
if ep.IPAMConfig != nil && ep.IPAMConfig.IPv4Address != "" {
staticIP := net.ParseIP(ep.IPAMConfig.IPv4Address)
netInfo.StaticIP = &staticIP
}
// If MAC address is provided
if len(ep.MacAddress) > 0 {
staticMac, err := net.ParseMAC(ep.MacAddress)

View file

@ -0,0 +1,17 @@
version: "3.2"
services:
test:
image: alpine
networks:
net1:
ipv4_address: 10.123.0.253
tty: true
command: ["top"]
networks:
net1:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.123.0.0/24

View file

@ -0,0 +1,4 @@
# -*- bash -*-
podman container inspect ipam_set_ip_test_1 --format '{{ .NetworkSettings.Networks.ipam_set_ip_net1.IPAddress }}'
like "$output" "10.123.0.253" "$testname : ip address is set"