IoT Greengrass Docker deployment: If I change deployment to run a different docker component or different version thereof, the old docker container keeps running locally.

0

Hi,

I am using AWS IoT Greengrass to deploy a docker image that I saved in a private ECR repo to my Raspberry Pi. The deployment works fine. However, if I change the deployment (i.e. revise it) to run a different image and not the old one anymore, the old container still keeps running locally. I obviously want the old docker container to stop if I haven't included it in my deployment anymore. This only happens if I shut down the RPI and restart it. How can Imake sure the old container stops immediately.

My component recipe looks as follows, do I need to change anything therein? For completeness: The Docker container runs a Python script that enters an infinite while loop which prints "Hello, world!" every second. Maybe the continuous loop is the problem but I don't think so as I am able to stop the container through docker stop.

{
	"RecipeFormatVersion": "2020-01-25",
	"ComponentName": "com.example.MyPrivateDockerComponent_revised",
	"ComponentVersion": "1.0.4",
	"ComponentType": "aws.greengrass.generic",
	"ComponentDescription": "A component that runs a Docker container from a private Amazon ECR image revised.",
	"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 --sig-proxy=True 242944196659.dkr.ecr.eu-central-1.amazonaws.com/test_repo:latest",
				"Stop": "docker stop $(docker ps -q --filter ancestor=242944196659.dkr.ecr.eu-central-1.amazonaws.com/test_repo:latest)",
				"Destroy": "docker rm $(docker ps -a -q --filter ancestor=242944196659.dkr.ecr.eu-central-1.amazonaws.com/test_repo:latest)"
			},
			"Artifacts": [
				{
					"Uri": "docker:242944196659.dkr.ecr.eu-central-1.amazonaws.com/test_repo:latest",
					"Unarchive": "NONE",
					"Permission": {
						"Read": "OWNER",
						"Execute": "NONE"
					}
				}
			]
		}
	],
	"Lifecycle": {}
}
已提問 1 年前檢視次數 325 次
1 個回答
1
已接受的答案

Hello,

The problem is that you're using stop and destroy which I'm not sure where you got those from. Refer to the recipe reference here: https://docs.aws.amazon.com/greengrass/v2/developerguide/component-recipe-reference.html#recipe-format, you should use shutdown as the key to stop the component.

Cheers,

Michael

AWS
專家
已回答 1 年前
profile picture
專家
已審閱 1 個月前

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

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

回答問題指南