Docker: comstrek/air doesn’t supported linux/arm64 in golang with Macbook M1 (Solved)
Preface
I want to build golang application with docker and installing library live reload apps with comsrek/air
. And I use Macbook M1.
My dockerfile
like this:
FROM golang:1.16ENV FILE_LOC=./.dev/.gql.air.tomlENV GROUP=companyENV SERVICE=my-serviceRUN apt update && apt upgrade -y && \ apt install -y git \ make openssh-clientWORKDIR /go/src/github.com/${GROUP}/${SERVICE}RUN curl -fLo install.sh https://raw.githubusercontent.com/cosmtrek/air/master/install.sh \ && chmod +x install.sh && sh install.sh && cp ./bin/air /bin/airCMD air -c $FILE_LOC
Problem
When I run the dockerfile, I got this error when trying to install comstrek/air:
ERROR [4/4] RUN curl -fLo install.sh https://raw.githubusercontent.com/cosmtrek/air/master/install.sh && chmod +x install.sh && sh install.sh && cp 0.7s
------
> [4/4] RUN curl -fLo install.sh https://raw.githubusercontent.com/cosmtrek/air/master/install.sh && chmod +x install.sh && sh install.sh && cp ./bin/air /bin/air:
#6 0.275 % Total % Received % Xferd Average Speed Time Time Time Current
#6 0.275 Dload Upload Total Spent Left Speed
100 9262 100 9262 0 0 22590 0 --:--:-- --:--:-- --:--:-- 22535
#6 0.712 cosmtrek/air crit platform linux/arm64 is not supported. Make sure this script is up-to-date and file request at https://github.com/cosmtrek/air/issues/new
------
executor failed running [/bin/sh -c curl -fLo install.sh https://raw.githubusercontent.com/cosmtrek/air/master/install.sh && chmod +x install.sh && sh install.sh && cp ./bin/air /bin/air]: exit code: 1
ERROR: Service 'campaign-gql' failed to build : Build failed
make: *** [services-up] Error 1
The problem is the docker was build images with arch
linux/arm64
but the library comstrek/air not supportedlinux/arm64
for currently.
There are supported arch in comstrek/air:
darwin/amd64) BINARIES="air" ;; darwin/arm64) BINARIES="air" ;; linux/386) BINARIES="air" ;; linux/amd64) BINARIES="air" ;; windows/386) BINARIES="air" ;; windows/amd64) BINARIES="air" ;;
Installation script: https://github.com/cosmtrek/air/blob/master/install.sh
Known Issue
Docker: Not all images are available for ARM64 architecture. You can add
--platform linux/amd64
to run an Intel image under emulation. In particular, the mysql image is not available for ARM64. You can work around this issue by using a mariadb image. — https://docs.docker.com/docker-for-mac/apple-silicon/
Solving
As docker says. I should setup the dockerfile to build with linux/amd64
(one of supported arch). And I change the dockerfile like this:
FROM --platform=linux/amd64 golang:1.16
And your images will be arch with linux/amd64
. And the application also running.
Nice ! Have a great time !
Source: