Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

You want to build a Docker image from Python in CI and push it to ECR. What does the script need?

IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → Auth to ECR plus build and push.

What I'd do →

  1. Get a token: ecr.get_authorization_token() returns base64 AWS:<password> and the proxy endpoint.
  2. docker.from_env().login(username="AWS", password=pw, registry=endpoint).
  3. Build with images.build(path=".", tag=f"{repo}:{sha}") (or shell out to docker buildx build for BuildKit features), then images.push(repo, tag=sha, stream=True, decode=True) and check each line for error.
  4. In GitHub Actions, the official aws-actions/amazon-ecr-login plus docker/build-push-action is simpler.

Why → The push stream reports errors inline; ignoring it hides failures.

Interview tip → Mention checking the push stream for errorDetail.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation