Skip to content

Commit 5cd7928

Browse files
committed
Updated backup to include ports
1 parent 61409a8 commit 5cd7928

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

backup/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,23 @@ func recreateContainerFromConfig(containerName string, imageFilePath string, con
277277
privFlag = "--privileged"
278278
}
279279

280+
portMappings := hostConfig["PortBindings"].(map[string]interface{})
281+
var ports []string
282+
for port, bindings := range portMappings {
283+
for _, binding := range bindings.([]interface{}) {
284+
hostBinding := binding.(map[string]interface{})
285+
hostIP := hostBinding["HostIp"].(string)
286+
ports = append(ports, fmt.Sprintf("-p %s:%s:%s", hostIP, hostBinding["HostPort"].(string), port))
287+
}
288+
}
289+
280290
args := []string{"run", "-d", "--name", quoteArgument(containerName), privFlag}
281291
args = append(args, envs...)
282292
args = append(args, volumes...)
283293
args = append(args, capabilities...)
284294
args = append(args, deviceMappings...)
285295
args = append(args, securityOpts...)
296+
args = append(args, ports...)
286297
args = append(args, quoteArgument(imageName))
287298

288299
podmanCommand := strings.Join(args, " ")

0 commit comments

Comments
 (0)