'Building amd64 docker image in M1 machine throws errors

I'm trying to build a amd64 docker image so that I can deploy it on ECS. I used the command docker buildx build --platform linux/amd64 -t {image}:{version}, but it throws these errors:

 > [ 3/13] RUN set -ex;         apt-get update;         apt-get install -y --no-install-recommends software-properties-common; add-apt-repository ppa:deadsnakes/ppa:
#0 0.225 + apt-get update
#0 42.18 Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease
#0 42.18   Connection failed [IP: 91.189.91.38 80]
#0 51.75 Err:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
#0 51.75   Connection failed [IP: 185.125.190.36 80]
#0 83.22 Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
#0 83.22   Connection failed [IP: 185.125.190.39 80]
#0 124.2 Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
#0 124.2   Connection failed [IP: 91.189.91.38 80]
#0 124.3 Reading package lists...
#0 124.4 W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Connection failed [IP: 91.189.91.38 80]
#0 124.4 W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Connection failed [IP: 185.125.190.39 80]
#0 124.4 W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Connection failed [IP: 91.189.91.38 80]
#0 124.4 W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Connection failed [IP: 185.125.190.36 80]
#0 124.4 W: Some index files failed to download. They have been ignored, or old ones used instead.
#0 124.4 + apt-get install -y --no-install-recommends software-properties-common
#0 124.5 Reading package lists...
#0 124.6 Building dependency tree...
#0 124.6 Reading state information...
#0 124.6 Package software-properties-common is not available, but is referred to by another package.
#0 124.6 This may mean that the package is missing, has been obsoleted, or
#0 124.6 is only available from another source
#0 124.6
#0 124.6 E: Package 'software-properties-common' has no installation candidate
------
error: failed to solve: executor failed running [/bin/sh -c set -ex;    apt-get update;     apt-get install -y --no-install-recommends software-properties-common;  add-apt-repository ppa:deadsnakes/ppa]: exit code: 100

If I switch platform to linux/arm64, building an image works correctly, but I get this error from AWS: standard_init_linux.go:228: exec user process caused: exec format error (I have #!/bin/bash inside of my script file and it has been worked fine before I used M1 mac.)

I'd appreciate your help. Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source