Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit ef115cc

Browse files
committed
Add flags for create command
- force-recreate - no-recreate Signed-off-by: Vincent Demeester <[email protected]>
1 parent 4298aee commit ef115cc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cli/command/command.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ func CreateCommand(factory app.ProjectFactory) cli.Command {
1212
Name: "create",
1313
Usage: "Create all services but do not start",
1414
Action: app.WithProject(factory, app.ProjectCreate),
15+
Flags: []cli.Flag{
16+
cli.BoolFlag{
17+
Name: "no-recreate",
18+
Usage: "If containers already exist, don't recreate them. Incompatible with --force-recreate.",
19+
},
20+
cli.BoolFlag{
21+
Name: "force-recreate",
22+
Usage: "Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.",
23+
},
24+
},
1525
}
1626
}
1727

@@ -239,7 +249,7 @@ func Populate(context *project.Context, c *cli.Context) {
239249

240250
if c.Command.Name == "logs" {
241251
context.Log = true
242-
} else if c.Command.Name == "up" {
252+
} else if c.Command.Name == "up" || c.Command.Name == "create" {
243253
context.Log = !c.Bool("d")
244254
context.NoRecreate = c.Bool("no-recreate")
245255
context.ForceRecreate = c.Bool("force-recreate")

docker/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,22 @@ func (s *Service) DependentServices() []project.ServiceRelationship {
4141

4242
// Create implements Service.Create.
4343
func (s *Service) Create() error {
44+
containers, err := s.collectContainers()
45+
if err != nil {
46+
return err
47+
}
48+
4449
imageName, err := s.build()
4550
if err != nil {
4651
return err
4752
}
4853

54+
if len(containers) != 0 {
55+
return s.eachContainer(func(c *Container) error {
56+
return s.recreateIfNeeded(imageName, c)
57+
})
58+
}
59+
4960
_, err = s.createOne(imageName)
5061
return err
5162
}

0 commit comments

Comments
 (0)