@@ -42,7 +42,10 @@ import (
42
42
"github.com/docker/api/errdefs"
43
43
)
44
44
45
- const singleContainerName = "single--container--aci"
45
+ const (
46
+ singleContainerName = "single--container--aci"
47
+ composeContainerSeparator = "_"
48
+ )
46
49
47
50
// ErrNoSuchContainer is returned when the mentioned container does not exist
48
51
var ErrNoSuchContainer = errors .New ("no such container" )
@@ -135,7 +138,7 @@ func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.C
135
138
if * container .Name == singleContainerName {
136
139
containerID = * containerGroup .Name
137
140
} else {
138
- containerID = * containerGroup .Name + "_" + * container .Name
141
+ containerID = * containerGroup .Name + composeContainerSeparator + * container .Name
139
142
}
140
143
status := "Unknown"
141
144
if container .InstanceView != nil && container .InstanceView .CurrentState != nil {
@@ -155,6 +158,10 @@ func (cs *aciContainerService) List(ctx context.Context, _ bool) ([]containers.C
155
158
}
156
159
157
160
func (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
+
158
165
var ports []types.ServicePortConfig
159
166
for _ , p := range r .Ports {
160
167
ports = append (ports , types.ServicePortConfig {
@@ -204,7 +211,7 @@ func (cs *aciContainerService) Stop(ctx context.Context, containerName string, t
204
211
}
205
212
206
213
func getGroupAndContainerName (containerID string ) (groupName string , containerName string ) {
207
- tokens := strings .Split (containerID , "_" )
214
+ tokens := strings .Split (containerID , composeContainerSeparator )
208
215
groupName = tokens [0 ]
209
216
if len (tokens ) > 1 {
210
217
containerName = tokens [len (tokens )- 1 ]
@@ -258,7 +265,11 @@ func (cs *aciContainerService) Logs(ctx context.Context, containerName string, r
258
265
}
259
266
260
267
func (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 )
262
273
if err != nil {
263
274
return err
264
275
}
@@ -315,9 +326,16 @@ func (cs *aciComposeService) Up(ctx context.Context, opts cli.ProjectOptions) er
315
326
}
316
327
317
328
func (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
321
339
}
322
340
logrus .Debugf ("Down on project with name %q\n " , project .Name )
323
341
0 commit comments