diff --git a/pkg/project/batch.go b/pkg/project/batch.go index a2d236bb..c692b905 100644 --- a/pkg/project/batch.go +++ b/pkg/project/batch.go @@ -164,8 +164,6 @@ func (s *Batch) RunContainer(stop <-chan bool, updates chan<- ServiceRunUpdate, } hostConfig := &container.HostConfig{ - // TODO: make this configurable through an cmd param - AutoRemove: true, // LogConfig: *f.ce.Logger(f.runCtx).Config(), LogConfig: container.LogConfig{ Type: "json-file", @@ -252,6 +250,19 @@ func (s *Batch) RunContainer(stop <-chan bool, updates chan<- ServiceRunUpdate, return nil } + // defer removing container so logs can be retrieved, used instead of AutoRemove + defer func() { + err = dockerClient.ContainerRemove(context.Background(), containerId, container.RemoveOptions{}) + if err != nil { + updates <- ServiceRunUpdate{ + ServiceName: s.Name, + Label: s.GetFilePath(), + Status: ServiceRunStatus_Error, + Err: err, + } + } + }() + err = dockerClient.ContainerStart(context.TODO(), containerId, container.StartOptions{}) if err != nil { updates <- ServiceRunUpdate{ diff --git a/pkg/project/service.go b/pkg/project/service.go index 505bd118..03eac737 100644 --- a/pkg/project/service.go +++ b/pkg/project/service.go @@ -336,8 +336,6 @@ func (s *Service) RunContainer(stop <-chan bool, updates chan<- ServiceRunUpdate } hostConfig := &container.HostConfig{ - // TODO: make this configurable through an cmd param - AutoRemove: true, // LogConfig: *f.ce.Logger(f.runCtx).Config(), LogConfig: container.LogConfig{ Type: "json-file", @@ -424,6 +422,19 @@ func (s *Service) RunContainer(stop <-chan bool, updates chan<- ServiceRunUpdate return nil } + // defer removing container so logs can be retrieved, used instead of AutoRemove + defer func() { + err = dockerClient.ContainerRemove(context.Background(), containerId, container.RemoveOptions{}) + if err != nil { + updates <- ServiceRunUpdate{ + ServiceName: s.Name, + Label: s.GetFilePath(), + Status: ServiceRunStatus_Error, + Err: err, + } + } + }() + err = dockerClient.ContainerStart(context.TODO(), containerId, container.StartOptions{}) if err != nil { updates <- ServiceRunUpdate{