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

Commit e5bba16

Browse files
committed
Improve logging when there are other tasks running locally
1 parent fc87d82 commit e5bba16

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

ecs-cli/modules/cli/local/local_app.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ func Create(c *cli.Context) {
3838
// If the container is not running, this command creates a new network for all local ECS tasks to join
3939
// and communicate with the Amazon ECS Local Endpoints container.
4040
func Up(c *cli.Context) {
41-
docker, err := client.NewEnvClient() // Temporary client created to test network.Setup()
41+
// TODO move these clients to a separate file leveraging the DOCKER_API_VERSION,
42+
// these clients are created to test the local network for now.
43+
// See https://github.com/awslabs/amazon-ecs-local-container-endpoints/blob/master/local-container-endpoints/clients/docker/client.go#L49
44+
docker, err := client.NewEnvClient()
4245
if err != nil {
4346
logrus.Fatal("Could not connect to docker", err)
4447
}
@@ -49,7 +52,10 @@ func Up(c *cli.Context) {
4952
//
5053
// If the user stops the last running task in the local network then also remove the network.
5154
func Stop(c *cli.Context) {
52-
docker, err := client.NewEnvClient() // Temporary client created to test network.Teardown()
55+
// TODO move these clients to a separate file leveraging the DOCKER_API_VERSION,
56+
// these clients are created to test the local network for now.
57+
// See https://github.com/awslabs/amazon-ecs-local-container-endpoints/blob/master/local-container-endpoints/clients/docker/client.go#L49
58+
docker, err := client.NewEnvClient()
5359
if err != nil {
5460
logrus.Fatal("Could not connect to docker", err)
5561
}

ecs-cli/modules/cli/local/network/teardown.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func hasRunningTasksInNetwork(d networkInspector) bool {
7676

7777
if len(resp.Containers) > 1 {
7878
// Has other containers running in the network
79+
logrus.Infof("%d other task(s) running locally, skipping network removal.", len(resp.Containers)-1)
7980
return true
8081
}
8182

@@ -99,7 +100,7 @@ func stopEndpointsContainer(d containerStopper) {
99100
err := d.ContainerStop(ctx, localEndpointsContainerName, nil)
100101
if err != nil {
101102
if strings.Contains(strings.ToLower(err.Error()), "no such container") {
102-
// The container was removed, do nothing.
103+
// The containers in the network were already stopped by the user using "docker stop", do nothing.
103104
return
104105
}
105106
logrus.Fatalf("Failed to stop %s container due to %v", localEndpointsContainerName, err)
@@ -122,7 +123,7 @@ func removeEndpointsContainer(d containerRemover) {
122123
err := d.ContainerRemove(ctx, localEndpointsContainerName, types.ContainerRemoveOptions{})
123124
if err != nil {
124125
if strings.Contains(strings.ToLower(err.Error()), "no such container") {
125-
// The container was removed, do nothing.
126+
// The containers in the network were already removed by the user using "docker rm", do nothing.
126127
return
127128
}
128129
logrus.Fatalf("Failed to remove %s container due to %v", localEndpointsContainerName, err)

0 commit comments

Comments
 (0)