Unknown flag: --platform when run in pipeline to AWS

Hi,

I am using macbook M1 and I got the following error when try executing the command below in docker:

docker build -t $APP_NAME:$CI_PIPELINE_IID-amd64 .

error:

standard_init_linux.go:228: exec user process caused: exec format error

I google and realize that I got to use platform amd/64. Then i performed the cmd below and it works:

docker buildx build --platform=linux/amd64 -t $APP_NAME:$CI_PIPELINE_IID-amd64 .

Again, the command above I tested in my terminal worked successfully then I try to copy into .gitlab.ci.yml. However, it returns me error below:

unknown flag: --platform

The details:

  • Developer: Macbook M1
  • Container: ECR
  • Server: ECS

The content in .gitlab.ci.yml:

variables:
DOCKER_REGISTRY: x
AWS_DEFAULT_REGION: x
APP_NAME: sample-nodejs-app
DOCKER_HOST: tcp://docker:2375

publish:
image:
name: amazon/aws-cli
entrypoint: [“”]
services:
- docker:dind
before_script:
- amazon-linux-extras install docker
- aws --version
- docker --version
script:
- aws ecr get-login-password | docker login --username AWS --password-stdin $DOCKER_REGISTRY
- docker build --platform linux/amd64 -t $APP_NAME:$CI_PIPELINE_IID .
- docker tag $APP_NAME:$CI_PIPELINE_IID $DOCKER_REGISTRY/$APP_NAME:$CI_PIPELINE_IID
- docker push $DOCKER_REGISTRY/$APP_NAME:$CI_PIPELINE_IID

Some output from pipeline:

$ aws --version
aws-cli/2.7.27 Python/3.9.11 Linux/5.4.109+ docker/x86_64.amzn.2 prompt/off

$ docker --version

Docker version 20.10.17, build 100c701

aws ecr get-login-password | docker login --username AWS --password-stdin $DOCKER_REGISTRY

WARNING! Your password will be stored unencrypted in /root/.docker/config.json.

Configure a credential helper to remove this warning. See docker login | Docker Docs

Login Succeeded

$ docker buildx build --platform linux/amd64 --push -t $DOCKER_REGISTRY/$APP_NAME:$CI_PIPELINE_IID .

unknown flag: --platform

See ‘docker --help’.

Usage: docker [OPTIONS] COMMAND

May I know is it due to pipeline not compatible? Is there any solution?

1 Like

hi there, did you find a solution for this problem? I’m facing the same error with a different build script.

Thanks

Hi i solved by installing buildx before script:

    # Install buildx
    # ref: https://travis-ci.community/t/docker-buildx-problems/11017
    - mkdir -vp ~/.docker/cli-plugins/
    - curl --silent -L "https://github.com/docker/buildx/releases/download/v0.3.0/buildx-v0.3.0.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
    - chmod a+x ~/.docker/cli-plugins/docker-buildx

Hope it helps and good luck!

1 Like

Awesome! It worked to me too. Thanks

This is an official blog post from docker about how to build in Gitlab CI for different platforms: Multi-arch build, what about GitLab CI? | Docker It is easier solution and worked for me

does not work sadly. unknown shorthand -t. works fine locally