@@ -236,6 +236,7 @@ func (engine *DockerTaskEngine) synchronizeState() {
236
236
log .Warn ("Could not find matching container for expected" , "name" , cont .DockerName )
237
237
} else {
238
238
cont .DockerID = describedCont .ID
239
+ cont .Container .SetKnownStatus (dockerStateToState (describedCont .State ))
239
240
// update mappings that need dockerid
240
241
engine .state .AddContainer (cont , task )
241
242
engine .imageManager .RecordContainerReference (cont .Container )
@@ -558,15 +559,24 @@ func (engine *DockerTaskEngine) createContainer(task *api.Task, container *api.C
558
559
client = client .WithVersion (dockerclient .DockerVersion (* container .DockerConfig .Version ))
559
560
}
560
561
561
- // Resolve HostConfig
562
- // we have to do this in create, not start, because docker no longer handles
563
- // merging create config with start hostconfig the same; e.g. memory limits
564
- // get lost
562
+ dockerContainerName := ""
565
563
containerMap , ok := engine .state .ContainerMapByArn (task .Arn )
566
564
if ! ok {
567
565
containerMap = make (map [string ]* api.DockerContainer )
566
+ } else {
567
+ // looking for container that has docker name but not created
568
+ for _ , v := range containerMap {
569
+ if v .Container .Name == container .Name {
570
+ dockerContainerName = v .DockerName
571
+ break
572
+ }
573
+ }
568
574
}
569
575
576
+ // Resolve HostConfig
577
+ // we have to do this in create, not start, because docker no longer handles
578
+ // merging create config with start hostconfig the same; e.g. memory limits
579
+ // get lost
570
580
hostConfig , hcerr := task .DockerHostConfig (container , containerMap )
571
581
if hcerr != nil {
572
582
return DockerContainerMetadata {Error : api .NamedError (hcerr )}
@@ -586,28 +596,30 @@ func (engine *DockerTaskEngine) createContainer(task *api.Task, container *api.C
586
596
config .Labels [labelPrefix + "task-definition-version" ] = task .Version
587
597
config .Labels [labelPrefix + "cluster" ] = engine .cfg .Cluster
588
598
589
- name := ""
590
- for i := 0 ; i < len (container .Name ); i ++ {
591
- c := container .Name [i ]
592
- if ! ((c <= '9' && c >= '0' ) || (c >= 'a' && c <= 'z' ) || (c >= 'A' && c <= 'Z' ) || (c == '-' )) {
593
- continue
599
+ if dockerContainerName == "" {
600
+ name := ""
601
+ for i := 0 ; i < len (container .Name ); i ++ {
602
+ c := container .Name [i ]
603
+ if ! ((c <= '9' && c >= '0' ) || (c >= 'a' && c <= 'z' ) || (c >= 'A' && c <= 'Z' ) || (c == '-' )) {
604
+ continue
605
+ }
606
+ name += string (c )
594
607
}
595
- name += string (c )
596
- }
597
608
598
- containerName : = "ecs-" + task .Family + "-" + task .Version + "-" + name + "-" + utils .RandHex ()
609
+ dockerContainerName = "ecs-" + task .Family + "-" + task .Version + "-" + name + "-" + utils .RandHex ()
599
610
600
- // Pre-add the container in case we stop before the next, more useful,
601
- // AddContainer call. This ensures we have a way to get the container if
602
- // we die before 'createContainer' returns because we can inspect by
603
- // name
604
- engine .state .AddContainer (& api.DockerContainer {DockerName : containerName , Container : container }, task )
605
- seelog .Infof ("Created container name mapping for task %s - %s -> %s" , task , container , containerName )
606
- engine .saver .ForceSave ()
611
+ // Pre-add the container in case we stop before the next, more useful,
612
+ // AddContainer call. This ensures we have a way to get the container if
613
+ // we die before 'createContainer' returns because we can inspect by
614
+ // name
615
+ engine .state .AddContainer (& api.DockerContainer {DockerName : dockerContainerName , Container : container }, task )
616
+ seelog .Infof ("Created container name mapping for task %s - %s -> %s" , task , container , dockerContainerName )
617
+ engine .saver .ForceSave ()
618
+ }
607
619
608
- metadata := client .CreateContainer (config , hostConfig , containerName , createContainerTimeout )
620
+ metadata := client .CreateContainer (config , hostConfig , dockerContainerName , createContainerTimeout )
609
621
if metadata .DockerID != "" {
610
- engine .state .AddContainer (& api.DockerContainer {DockerID : metadata .DockerID , DockerName : containerName , Container : container }, task )
622
+ engine .state .AddContainer (& api.DockerContainer {DockerID : metadata .DockerID , DockerName : dockerContainerName , Container : container }, task )
611
623
}
612
624
seelog .Infof ("Created docker container for task %s: %s -> %s" , task , container , metadata .DockerID )
613
625
return metadata
0 commit comments