@@ -45,6 +45,18 @@ type upOptions struct {
4545 Detach bool
4646 Environment []string
4747 removeOrphans bool
48+ forceRecreate bool
49+ noRecreate bool
50+ }
51+
52+ func (o upOptions ) recreateStrategy () string {
53+ if o .noRecreate {
54+ return compose .RecreateNever
55+ }
56+ if o .forceRecreate {
57+ return compose .RecreateForce
58+ }
59+ return compose .RecreateDiverged
4860}
4961
5062func upCommand (p * projectOptions , contextType string ) * cobra.Command {
@@ -59,6 +71,9 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
5971 RunE : func (cmd * cobra.Command , args []string ) error {
6072 switch contextType {
6173 case store .LocalContextType , store .DefaultContextType , store .EcsLocalSimulationContextType :
74+ if opts .forceRecreate && opts .noRecreate {
75+ return fmt .Errorf ("--force-recreate and --no-recreate are incompatible" )
76+ }
6277 return runCreateStart (cmd .Context (), opts , args )
6378 default :
6479 return runUp (cmd .Context (), opts , args )
@@ -71,8 +86,13 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
7186 flags .BoolVar (& opts .Build , "build" , false , "Build images before starting containers." )
7287 flags .BoolVar (& opts .removeOrphans , "remove-orphans" , false , "Remove containers for services not defined in the Compose file." )
7388
74- if contextType == store .AciContextType {
89+ switch contextType {
90+ case store .AciContextType :
7591 flags .StringVar (& opts .DomainName , "domainname" , "" , "Container NIS domain name" )
92+ case store .LocalContextType , store .DefaultContextType , store .EcsLocalSimulationContextType :
93+ flags .BoolVar (& opts .forceRecreate , "force-recreate" , false , "Recreate containers even if their configuration and image haven't changed." )
94+ flags .BoolVar (& opts .noRecreate , "no-recreate" , false , "If containers already exist, don't recreate them. Incompatible with --force-recreate." )
95+
7696 }
7797
7898 return upCmd
@@ -101,6 +121,7 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
101121 _ , err = progress .Run (ctx , func (ctx context.Context ) (string , error ) {
102122 return "" , c .ComposeService ().Create (ctx , project , compose.CreateOptions {
103123 RemoveOrphans : opts .removeOrphans ,
124+ Recreate : opts .recreateStrategy (),
104125 })
105126 })
106127 if err != nil {
0 commit comments