Greengress IoT Deployment while deploying docker container from ECR doesn't stop previous run

0

I have my docker container hosted in ECR, my component recipe is:

{
  "RecipeFormatVersion": "2020-01-25",
  "ComponentName": <component-name>,
  "ComponentVersion": "1.0.46",
  "ComponentType": "aws.greengrass.generic",
  "ComponentDescription": "A component that runs a Docker container from a private Amazon ECR image.",
  "ComponentPublisher": "Amazon",
  "ComponentDependencies": {
    "aws.greengrass.DockerApplicationManager": {
      "VersionRequirement": ">=2.0.0 <2.1.0",
      "DependencyType": "HARD"
    },
    "aws.greengrass.TokenExchangeService": {
      "VersionRequirement": ">=2.0.0 <2.1.0",
      "DependencyType": "HARD"
    }
  },
  "Manifests": [
    {
      "Platform": {
        "os": "all"
      },
      "Lifecycle": {
        "Run": "docker run --rm --net=host <image_name>",
        "Shutdown": "docker stop $(docker ps -a -q --filter ancestor=<image_name> --format=\"{{.ID}}\")"
      },
      "Artifacts": [
        {
          "Uri": <image_uri>,
          "Unarchive": "NONE",
          "Permission": {
            "Read": "OWNER",
            "Execute": "NONE"
          }
        }
      ]
    }
  ],
  "Lifecycle": {}
}

My question is, sometimes when the internet connection is slow, the previous deployment's docker run doesn't stop, so I end up having 2 running docker containers. How can I ensure the previous one stops, I have added -rm and a SHUTDOWN command.

已提問 2 年前檢視次數 271 次
2 個答案
0

Hi, can you try forwarding signals to the container itself?

Add --sig-proxy=true to your run command. You can remove the shutdown phase.

AWS
已回答 2 年前
  • Thanks for the response. Doesn't work unfortunately, I still have 2 containers running. I realized this happens when a new version of the docker container is published to ECR and then deployed.

  • Is your process able to process the SIGTERM which is sent by Greengrass? What happens when docker stop is run during shutdown?

0

Hi!

You're on the right approach. In the recipe file above, you are mixing Run with Shutdown. Run stands on its own and is good for foreground processes. But in that case, you must honor and process the SIGTERM received.

With Shutdown you would use Startup instead of Run. For that, Startup would do a docker run -d --name CONTAINER_NAME and name the container, while Shutdown would do a docker stop CONTAINER_NAME.

In summary, Run requires you to run the component in foreground and process SIGTERMs when Greengrass issues a stop to the component. Startup and Shutdown require a exit code of 0 for each, and your Shutdown process would need to know the running container (or process).

HTH!

AWS
Gavin_A
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南