@@ -42,7 +42,10 @@ import (
4242 "github.com/docker/api/errdefs"
4343)
4444
45- const singleContainerName = "single--container--aci"
45+ const (
46+ singleContainerName = "single--container--aci"
47+ composeContainerSeparator = "_"
48+ )
4649
4750// ErrNoSuchContainer is returned when the mentioned container does not exist
4851var ErrNoSuchContainer = errors .New ("no such container" )
@@ -135,7 +138,7 @@ func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.C
135138 if * container .Name == singleContainerName {
136139 containerID = * containerGroup .Name
137140 } else {
138- containerID = * containerGroup .Name + "_" + * container .Name
141+ containerID = * containerGroup .Name + composeContainerSeparator + * container .Name
139142 }
140143 status := "Unknown"
141144 if container .InstanceView != nil && container .InstanceView .CurrentState != nil {
@@ -155,6 +158,10 @@ func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.C
155158}
156159
157160func (cs * aciContainerService ) Run (ctx context.Context , r containers.ContainerConfig ) error {
161+ if strings .Contains (r .ID , composeContainerSeparator ) {
162+ return errors .New (fmt .Sprintf ("invalid container name. ACI container name cannot include %q" , composeContainerSeparator ))
163+ }
164+
158165 var ports []types.ServicePortConfig
159166 for _ , p := range r .Ports {
160167 ports = append (ports , types.ServicePortConfig {
@@ -204,7 +211,7 @@ func (cs *aciContainerService) Stop(ctx context.Context, containerName string, t
204211}
205212
206213func getGroupAndContainerName (containerID string ) (groupName string , containerName string ) {
207- tokens := strings .Split (containerID , "_" )
214+ tokens := strings .Split (containerID , composeContainerSeparator )
208215 groupName = tokens [0 ]
209216 if len (tokens ) > 1 {
210217 containerName = tokens [len (tokens )- 1 ]
@@ -258,7 +265,11 @@ func (cs *aciContainerService) Logs(ctx context.Context, containerName string, r
258265}
259266
260267func (cs * aciContainerService ) Delete (ctx context.Context , containerID string , _ bool ) error {
261- cg , err := deleteACIContainerGroup (ctx , cs .ctx , containerID )
268+ groupName , containerName := getGroupAndContainerName (containerID )
269+ if groupName != containerID {
270+ return errors .New (fmt .Sprintf ("cannot delete service %q from compose app %q, you must delete the entire compose app with docker compose down" , containerName , groupName ))
271+ }
272+ cg , err := deleteACIContainerGroup (ctx , cs .ctx , groupName )
262273 if err != nil {
263274 return err
264275 }
@@ -315,9 +326,16 @@ func (cs *aciComposeService) Up(ctx context.Context, opts cli.ProjectOptions) er
315326}
316327
317328func (cs * aciComposeService ) Down (ctx context.Context , opts cli.ProjectOptions ) error {
318- project , err := cli .ProjectFromOptions (& opts )
319- if err != nil {
320- return err
329+ var project types.Project
330+
331+ if opts .Name != "" {
332+ project = types.Project {Name : opts .Name }
333+ } else {
334+ fullProject , err := cli .ProjectFromOptions (& opts )
335+ if err != nil {
336+ return err
337+ }
338+ project = * fullProject
321339 }
322340 logrus .Debugf ("Down on project with name %q\n " , project .Name )
323341
0 commit comments