@@ -10,7 +10,6 @@ import (
1010 "github.com/docker/compose/v2/pkg/progress"
1111 "github.com/docker/docker/api/types/container"
1212 "github.com/docker/docker/pkg/jsonmessage"
13- "github.com/docker/docker/pkg/stringid"
1413 "github.com/psviderski/uncloud/internal/docker"
1514 machinedocker "github.com/psviderski/uncloud/internal/machine/docker"
1615 "github.com/psviderski/uncloud/internal/secret"
@@ -200,7 +199,7 @@ func toPullProgressEvent(jm jsonmessage.JSONMessage) *progress.Event {
200199}
201200
202201// InspectContainer returns the information about the specified container within the service.
203- // containerNameOrID can be name, ID, or truncated ID of the container.
202+ // containerNameOrID can be name, full ID, or ID prefix of the container.
204203func (cli * Client ) InspectContainer (
205204 ctx context.Context , serviceNameOrID , containerNameOrID string ,
206205) (api.MachineServiceContainer , error ) {
@@ -209,13 +208,23 @@ func (cli *Client) InspectContainer(
209208 return api.MachineServiceContainer {}, fmt .Errorf ("inspect service: %w" , err )
210209 }
211210
212- // TODO: support matching by any prefix of the container ID
211+ prefixMatchCandidates := []api. MachineServiceContainer {}
213212 for _ , c := range svc .Containers {
214213 if c .Container .ID == containerNameOrID ||
215- c .Container .Name == containerNameOrID ||
216- stringid .TruncateID (c .Container .ID ) == containerNameOrID {
214+ c .Container .Name == containerNameOrID {
217215 return c , nil
218216 }
217+
218+ if strings .HasPrefix (c .Container .ID , containerNameOrID ) {
219+ prefixMatchCandidates = append (prefixMatchCandidates , c )
220+ }
221+ }
222+
223+ if len (prefixMatchCandidates ) == 1 {
224+ return prefixMatchCandidates [0 ], nil
225+ } else if len (prefixMatchCandidates ) > 1 {
226+ return api.MachineServiceContainer {}, fmt .Errorf (
227+ "multiple containers found with ID prefix '%s'" , containerNameOrID )
219228 }
220229
221230 return api.MachineServiceContainer {}, api .ErrNotFound
0 commit comments