run service container in uncloud Docker network

This commit is contained in:
Pavel Sviderski
2024-11-14 19:19:50 +10:00
parent 035601d366
commit d31595820d
+8 -1
View File
@@ -6,10 +6,12 @@ import (
"fmt" "fmt"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/emptypb"
"slices" "slices"
"strings" "strings"
machinecore "uncloud/internal/machine"
"uncloud/internal/machine/api/pb" "uncloud/internal/machine/api/pb"
"uncloud/internal/secret" "uncloud/internal/secret"
) )
@@ -102,7 +104,12 @@ func (c *Client) RunService(ctx context.Context, opts *ServiceOptions) (RunServi
"uncloud.service.name": serviceName, "uncloud.service.name": serviceName,
}, },
} }
createResp, err := c.CreateContainer(ctx, config, nil, nil, nil, containerName) netConfig := &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
machinecore.DockerNetworkName: {},
},
}
createResp, err := c.CreateContainer(ctx, config, nil, netConfig, nil, containerName)
if err != nil { if err != nil {
return resp, fmt.Errorf("create container: %w", err) return resp, fmt.Errorf("create container: %w", err)
} }