Skip to content

Commit 5433f36

Browse files
committed
fix(container): set network mode when creating a container
1 parent fc393f9 commit 5433f36

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

cli/container/install.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ func (c *InstallCommand) RunE(cmd *cobra.Command, args []string) error {
138138
}
139139

140140
// Create shared network
141-
if err := cli.CreateSharedNetwork(ctx, commonNetwork); err != nil {
142-
return err
141+
if commonNetwork != "" {
142+
if err := cli.CreateSharedNetwork(ctx, commonNetwork); err != nil {
143+
return err
144+
}
143145
}
144146

145147
//
@@ -168,21 +170,26 @@ func (c *InstallCommand) RunE(cmd *cobra.Command, args []string) error {
168170
Labels: map[string]string{},
169171
}
170172

173+
networkConfig := make(map[string]*network.EndpointSettings)
174+
if commonNetwork != "" {
175+
slog.Info("Connecting container to common network.", "network", commonNetwork)
176+
networkConfig[commonNetwork] = &network.EndpointSettings{
177+
NetworkID: commonNetwork,
178+
}
179+
}
180+
171181
resp, err := cli.Client.ContainerCreate(
172182
ctx,
173183
containerConfig,
174184
&containerSDK.HostConfig{
175185
PublishAllPorts: true,
186+
NetworkMode: network.NetworkBridge,
176187
RestartPolicy: containerSDK.RestartPolicy{
177188
Name: containerSDK.RestartPolicyAlways,
178189
},
179190
},
180191
&network.NetworkingConfig{
181-
EndpointsConfig: map[string]*network.EndpointSettings{
182-
commonNetwork: {
183-
NetworkID: commonNetwork,
184-
},
185-
},
192+
EndpointsConfig: networkConfig,
186193
},
187194
nil,
188195
containerName,

0 commit comments

Comments
 (0)