Pushing a multi-platform image to ghcr.io results in an endless loop
If you build an image for multiple CPU architectures at the same time and use --push, the upload of the images will often get stuck in an endless loop.
The following line is printed over and over again:
error: failed to copy: failed to do request: Put "https://ghcr.io/v2/reconman/example-buildx-push/blobs/upload/a5521203-2c8d-49d5-bcde-d9ba8500a5b0?digest=sha256%3A1e1235e447358303a2d2975f6078eb4f82db3b64fe1ef840976f6033eac9a19f": write tcp 172.17.0.2:40356->140.82.113.33:443: write: connection reset by peer
I'm able to easily reproduce the issue by building a python-based image with all architectures allowed by the base image: https://github.com/reconman/example-buildx-push
I increased the number of layers by adding some RUN commands because I'm suspecting that it increases the failure chance.
When I changed --push to type=oci,dest=/tmp/image.tar and ran the following containerd commands manually, I encountered https://github.com/containerd/containerd/issues/2706, so it may be related to that?
sudo ctr i import --base-name ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} --digests --all-platforms /tmp/image.tar
while IFS= read -r line; do
sudo ctr i push --user "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" $line;
done <<< "${{ steps.meta.outputs.tags }}"
Here are the Github workflow logs with the Buildkit debug flag enabled: logs_1.zip
The following line is printed over and over again:
Looks like a temporary issue with the registry itself like moby/buildkit#2453 or https://github.com/docker/build-push-action/issues/487#issuecomment-948851225. Suggest to try again and also check for write and read access of GitHub Actions for repositories in the container settings.
Suggest to try again
Right now it's a game of luck. I spent a few hours retrying my workflow for one of my repos where I was building 2 Docker images like this and each Docker build job takes 20 minutes.
With an estimated 50 % success rate for each Dockerfile, the chance of both succeeding was 25 %.
Each time, I had to first wait 20 minutes for the build to finish and then check if the job is stuck or not. If it was stuck, I had to cancel the workflow and start the 20 minute build again.
The probability of failure increases with the number of buildx jobs in the workflow. If you copy the build job in the example a couple of times, the workflow success rate will drop to below 10 %. You can't retry jobs afaik, only workflows. A workaround for this would be to create different workflows for each Dockerfile, but that's not an optimal solution.
Right now it's a game of luck. I spent a few hours retrying my workflow for one of my repos where I was building 2 Docker images like this and each Docker build job takes 20 minutes.
Which repo? The one you post only have one run: https://github.com/reconman/example-buildx-push/actions

Here's the last commit before I switched to containerd commands https://github.com/RickDB/PlexAniSync/tree/e927ecd1a3d600a50bd466e5aad3aa130f03e9cd
I wonder if this could be linked to recent changes. Can you try with:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
buildkitd-flags: --debug
driver-opts: image=moby/buildkit:v0.9.1
Looks good in the example repo, now trying it in the main one: https://github.com/RickDB/PlexAniSync/actions/runs/1446106060
Going to sleep now, so I can only check on the status tomorrow morning. (Central European Time)
Seems to work reliably, although the Post step for buildx can't kill the build container:
error: Error response from daemon: cannot stop container: buildx_buildkit_builder-e8a74214-2281-4605-8e14-383fed083af30: container 62a9db71d461 PID 2102 is zombie and can not be killed. Use the --init option when creating containers to run an init inside the container that forwards signals and reaps processes
We have the same problem already the second day
#31 exporting to image
#31 2.922 error: failed to copy: failed to do request: Put "https://ghcr.io/v2/astucorp/astuvet/astuvet-front/blobs/upload/dfff18c8-dff5-46e2-87cc-b626cae5aa34?digest=sha256%3A99cb6712938b8d6ce3648923cd82f9a04fe6dc403c7bcd062e69c58ecf19fd79": write tcp 172.17.0.2:40536->140.82.112.34:443: write: connection reset by peer
#31 2.923 retrying in 1s
same as @NinaSekret here! I have frequent errors with "push" failing to export image to ghcr.io
name: Build and push to Github and ECR
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64
build-args: GHCR_PAT=${{ secrets.GPR_TOKEN }}
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/xxxx:main
xxxxxxx.dkr.ecr.us-east-1.amazonaws.com/everest/xxxx:dev-${{ github.sha }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache
I wonder if this could be linked to recent changes. Can you try with:
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 with: buildkitd-flags: --debug driver-opts: image=moby/buildkit:v0.9.1
I tried using v0.9.1 and it was able to push to ghcr, before I was getting
#21 exporting to image
#21 10.19 error: failed to copy: failed to do request: Put "ghcr.io/v2/***/nginx-ubi/blobs/upload/7a8c69f8-1810-461e-b06c-eff124697f60?digest=sha256%3A95f3a65224747afb7ca844ff6cc345d49ddc569c8f2be7566bbcece0cbdcb4b2": write tcp 172.17.0.2:34150->140.82.112.34:443: write: connection reset by peer
#21 10.19 retrying in 1s
linked to recent changes.
If it helps narrow down the time range of the change, I started experiencing this problem about a month ago. I am likewise using the master branch:
uses: docker/setup-buildx-action@v1
with:
driver-opts: >-
image=moby/buildkit:master
Hi @reconman,
I've forked your example-buildx-push repo, but haven't seen it fail yet.
https://github.com/jcansdale-test/example-buildx-push/actions
How often would you expect to see this error?
@jcansdale I applied crazy-max's fix above. Revert the last commit, then it will happen.
@reconman Was not able to repro myself using latest BuildKit (0.9.2) with your repo example so don't think it comes from there: https://github.com/crazy-max/example-buildx-push/runs/4192456629?check_suite_focus=true#step:7:879. Might be something flaky from the registry. Any recent changes from ghcr recently @markphelps?
@reconman I've commented out this line and set it to run every 15 minutes.
I'll keep and eye on it and see if it fails.
I'm observing those hangs myself, they are random, and restarting the build again and again will make it work eventually. Using v0.9.1 as suggested seems to have fixed it, but might have just been a fluke.
I'm not even doing anything multi-arch related.
The problem seems to pop up from time to time. And today it became obvious that it is a GitHub Packages issues. So you may check status page here https://www.githubstatus.com/ first and do not bother yourself by trying some workarounds. After status changed to operating normally all docker builds and pushes start working properly.