简体   繁体   中英

How to check if a docker image was pushed successfully from python script

I am using the "docker" library of python to push docker image to AWS ECR registry. This script runs in a scheduled manner. So I want to add an alerting step if the docker push fails. So how to check if the docker push failed or not? This is my code:

import docker
docker_client_aws = docker.from_env()
docker_client_aws.login(username=ecr_username, password=ecr_password, registry=ecr_url)
image.tag(ecr_repo_name, tag='latest')
push_log = docker_client_aws.images.push(ecr_repo_name, tag='latest')
print(push_log)

Echoing the comment, the library will raise an exception if anything goes wrong, as is standard in Python code. Assuming that's the whole script, the uncaught exception would reach the top level of the interpreter and it would print a stack trace and then exit with a non-0 return code so you can check via that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM