Articles

How to verify a container image before rollback without SSH

Verify the exact Docker image and checksum a file without starting the container, then confirm the stable app URL serves the expected deployment after rollback.

Updated

Verify the image before rollback, then verify the URL customers use after rollback. For a registry image, keep the immutable Linux/amd64 manifest digest and pull that exact reference. For a local image, keep the original Docker archive and its checksum. In both cases, compare the file inside the image with a checksum recorded independently at release time.

Get the runnable example on GitHub · Download the example

Quick start

  1. Build two images and record their identity and a known fixture checksum. The sample uses a stateless Go API that serves the actual file at /release.txt.
  2. Extract the file without running the image. Stop if the hash differs, even if the image has the expected tag.
  3. Deploy the verified artifacts to a disposable Gregale app. Record both deployment IDs. After rolling back to the first ID, verify the serving deployment and request the ordinary app URL.

This covers code and container files. It does not restore a database, volumes, secrets, or other external state. Keep the code and database rollback procedure separate.

1. Retain the artifact you actually deployed

For an image from a registry, record the immutable reference used for the deployment:

sh
IMAGE='ghcr.io/your-org/your-app@sha256:YOUR_MANIFEST_DIGEST'
docker pull --platform linux/amd64 "$IMAGE"
./verify-image.sh "$IMAGE" "$EXPECTED_FILE_SHA"

Use the Linux/amd64 image manifest digest. A multi-platform index digest and a platform-specific manifest digest are different values. A Docker image ID identifies the image configuration; it is not the digest printed by your registry. Likewise, a Git commit or a package SBOM does not prove the exact bytes of an application file.

Use only an artifact you already retained or are authorized to pull. This procedure cannot export a historical image from a provider-managed build. If the old artifact is gone, rebuilding from the same Git commit produces a new artifact that needs its own verification.

Run the example without a registry

Install Go 1.23 or later and Docker with Buildx support for Linux/amd64. From the example:

sh
./build-images.sh
V1_SHA=$(shasum -a 256 fixtures/v1.txt | awk '{print $1}')
V2_SHA=$(shasum -a 256 fixtures/v2.txt | awk '{print $1}')

./verify-image.sh gregale-rollback-proof:v1 "$V1_SHA"
./verify-image.sh gregale-rollback-proof:v2 "$V2_SHA"
./verify-image.sh gregale-rollback-proof:v1 "$V2_SHA" # must fail
shasum -a 256 out/v1.tar out/v2.tar > out/archive-sha256.txt

On Linux, use sha256sum if shasum is not installed. The script creates a stopped container and copies out one file. It neither starts the entrypoint nor connects to the running application. For a real release, get the expected checksum from a trusted CI artifact record. Calculating it from the same image you're checking would make the comparison meaningless.

2. Deploy the same artifacts

Use a new disposable app on an account that supports prebuilt images. Push the two verified Linux/amd64 images to a registry your account can pull from, then copy the immutable manifest digests from the push results or your CI release records. Pull each exact reference and run the file checksum again against it before deploying.

sh
APP='your-disposable-rollback-proof'
IMAGE_V1='ghcr.io/your-org/your-app@sha256:V1_MANIFEST_DIGEST'
IMAGE_V2='ghcr.io/your-org/your-app@sha256:V2_MANIFEST_DIGEST'

docker pull --platform linux/amd64 "$IMAGE_V1"
./verify-image.sh "$IMAGE_V1" "$V1_SHA"
docker pull --platform linux/amd64 "$IMAGE_V2"
./verify-image.sh "$IMAGE_V2" "$V2_SHA"

gregale --non-interactive --json deploy --name "$APP" --image "$IMAGE_V1" --yes
# Record the first deployment ID. Check GET /release returns release-v1.
gregale --non-interactive --json deploy --name "$APP" --image "$IMAGE_V2" --yes
# Record the second deployment ID. Wait for the rollout to finish.

Use the registry credentials guide if the registry is private. Keep the two pinned references and the deployment records together. If the platform reports a different digest, first establish whether it identifies the input manifest or a transformed artifact; record both rather than assuming they're interchangeable.

The Gregale CLI also supports deploy --image-archive out/v1.tar for accounts with local image upload enabled. Check the archive checksum before uploading. If Gregale says local image deploys are unavailable for your account, use the registry path above instead. An archive SHA-256 identifies the file you supplied, not the image digest reported by the platform.

3. Verify the stable URL after the rollback

First make sure the stable address serves release-v2. A deployment-specific URL can answer before traffic moves. Then roll back to the exact first deployment ID:

sh
gregale rollback "$APP" --to "$V1_DEPLOYMENT_ID" \
  --expected-current "$V2_DEPLOYMENT_ID" --wait
gregale release traffic status "$APP"

Check that the rollback finished and the first deployment now owns serving traffic. Call GET /release on the original app URL, not a deployment-specific address. If the app is private, use authorized invocation on that stable address or make the request with your credential in the authorization header. Never put a credential in the URL or a release record.

Compare the response bytes with the first fixture and require a successful HTTP status. The expected body is release-v1 followed by a newline. A generic health response or a successful probe pinned to the old deployment does not show that normal traffic actually switched.

What this example verifies

We built and inspected two Linux/amd64 images, rejected the wrong file checksum, and confirmed the first image returned the exact fixture bytes from a local HTTP request. The Scale test account rejected local image archive uploads before a release was created. We did not verify registry-backed deployment or hosted rollback for this example. The example checks one file and one route; it does not prove every file or behavior in the release.

Questions

How can I verify a file in a Docker image without SSH?

Pull the pinned Linux/amd64 image or load a verified archive, create a stopped container, copy out the file, and compare its SHA-256 with a trusted release record.

How do I confirm a container rollback really took effect?

Confirm that the completed rollback points to the intended deployment and that the stable app URL returns the exact expected response. A revision-specific probe is not enough.