How can I correctly specify the platform for my dockerfile?
Asked Answered
B

3

8

I'm trying to add the --platform=linux/amd64 flag to my dockerfile's FROM statement. I need to do this because I'm working on an m1 laptop and the default architecture (linux/arm64/v8) is not compatible with our prod machine. The whole line should be:

FROM --platform=linux/amd64 openjdk:11-jre-slim

This worked fine for my frontend repo (with node as the base image). However, in the backend repo, I'm getting this error:

<name chain> expected, got '-'

So it's like, not letting me add the flag at all for some reason.

IntelliJ IDEA, Java

Full backend dockerfile:

FROM --platform=linux/amd64 openjdk:11-jre-slim
COPY config/dev.yml /opt/dropwizard/
COPY build/libs/smerge-1.0-SNAPSHOT-all.jar /opt/dropwizard/
EXPOSE 8080
WORKDIR /opt/dropwizard
CMD ["java", "-jar", "smerge-1.0-SNAPSHOT-all.jar", "server", "dev.yml"]

The docker documentation on the --platform flag for dockerfiles says that:

The optional --platform flag can be used to specify the platform of the image in case FROM references a multi-platform image. For example, linux/amd64, linux/arm64, or windows/amd64. By default, the target platform of the build request is used.

Bombazine answered 18/1, 2022 at 10:45 Comment(5)
Could you please add your backend repo docker fileDotterel
Sure thing -- doneBombazine
What is your host platform (windows/linux/etc)? Which Docker do you use (ce/desktop and version)? Since the problem only occurs in a certain project, have you tried to move the necessary files away into a new directory and perform the build there?Sybilla
I can perform a build, I'm asking about the dockerfile specifically.Bombazine
My image built from M1 Mac won't run on Cloud Run, figured it was a platform issue. I passed the platform using docker buildx: docker buildx build --platform linux/amd64 --tag REPO:TAG . If your docker version doesn't come with buildx you have to install it - docs.docker.com/build/buildx/installPyatt
S
5

On Mac, I add this line to the .zprofile and that takes care of everything at once. Adding it to the .zprofile, for me, ensures the DOCKER_DEFAULT_PLATFORM is present in the environ on accessing the terminal.

export DOCKER_DEFAULT_PLATFORM=linux/amd64

Stifling answered 5/6, 2023 at 6:44 Comment(0)
A
4

Also, I use this cmd to build docker image from the apple silicon macbook.

docker build --platform=linux/amd64 -t mydockerimage .

No need for buildx

Aldine answered 22/8, 2023 at 12:42 Comment(0)
S
0

On a whim i put this in my Dockerfile

FROM --platform=linux/amd64 php:5.6-apache

I turned off Rosetta in Docker Desktop and built it and it worked fine. This way you can set it on a per image basis since it's slower. I'm not sure why it complains about Rosetta when building for amd64 but I guess it's not quite the same thing as running an amd64 program.

Saccharometer answered 2/10 at 17:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.