Skip to content

Commit 5d029d2

Browse files
committed
feat: add support for ports published via --publish-all (closes #6)
1 parent 5871d16 commit 5d029d2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

docker.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,15 @@ func getPortBinding(container types.ContainerJSON) (string, error) {
9595
}
9696
return v[0].HostPort, nil
9797
}
98+
99+
// check for a randomly set port via --publish-all
100+
if len(container.NetworkSettings.Ports) == 1 {
101+
for _, v := range container.NetworkSettings.Ports {
102+
if v != nil && len(v) == 1 && v[0].HostPort != "" {
103+
return v[0].HostPort, nil
104+
}
105+
}
106+
}
107+
98108
return "", errors.Errorf("no host-port binding found for container '%s'", container.Name)
99109
}

testing/publish-random.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Test a docker run command
4+
5+
docker run --rm -it \
6+
--label "traefik.enable=true" \
7+
--label "traefik.http.routers.nginx.rule=Host(\`nginx.local\`)" \
8+
--label "traefik.http.routers.nginx.tls=true" \
9+
--label "traefik.http.routers.nginx.tls.certresolver=default" \
10+
--publish-all \
11+
nginx:alpine

0 commit comments

Comments
 (0)