@@ -16,6 +16,8 @@ import (
1616 "time"
1717)
1818
19+ const PORT = "5665"
20+
1921type dockerCreator struct {
2022 logger * zap.Logger
2123 dockerClient * client.Client
@@ -59,11 +61,13 @@ func (i *dockerCreator) CreateIcinga2(name string) services.Icinga2Base {
5961 panic (err )
6062 }
6163
64+ port := utils .NewPortDecision (i .dockerClient , PORT )
65+
6266 cont , err := i .dockerClient .ContainerCreate (context .Background (), & container.Config {
6367 Image : dockerImage ,
6468 Hostname : name ,
6569 Env : []string {"ICINGA_MASTER=1" },
66- }, nil , & network.NetworkingConfig {
70+ }, & container. HostConfig { PublishAllPorts : port . Remote ()} , & network.NetworkingConfig {
6771 EndpointsConfig : map [string ]* network.EndpointSettings {
6872 networkName : {
6973 NetworkID : i .dockerNetworkId ,
@@ -90,10 +94,15 @@ func (i *dockerCreator) CreateIcinga2(name string) services.Icinga2Base {
9094 }
9195 logger .Debug ("started container" )
9296
97+ binding , err := port .Binding (context .Background (), i .dockerClient , cont .ID )
98+ if err != nil {
99+ logger .Fatal ("can't create port binding" , zap .Error (err ))
100+ }
101+
93102 n := & dockerInstance {
94103 info : info {
95- host : utils . MustString ( utils . DockerContainerAddress ( context . Background (), i . dockerClient , cont . ID )) ,
96- port : "5665" ,
104+ host : binding . Host ,
105+ port : binding . Port ,
97106 },
98107 icinga2Docker : i ,
99108 logger : logger ,
0 commit comments