63

I get the error:

failed to solve with frontend dockerfile.v0: failed to create LLB definition: no match for platform in manifest

when building the following Dockerfile:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8
COPY . /inetpub/wwwroot
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MiguelSlv
  • 14,067
  • 15
  • 102
  • 169

11 Answers11

80

The cause was simple. I had my Docker desktop running on Linux containers and the image was build from a Windows image.

Simply switching to Windows containers solved the problem.

The message is clueless, so I hope this save some time for others.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
  • 1
    I work on Windows WSL and i have an error like "failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to parse platform : "" is an invalid component of "": platform specifier component must match "^[A-Za-z0-9_-]+$": invalid argument", can you give more details plz – Mahmoud Oct 29 '21 at 15:21
  • 28
    For whoever is wondering, to switch from Linux to Windows containers you just have to right click on the Docker icon in your _system tray icons_ -- assuming you're in Windows -- and then click on "Switch to Windows containers..." – Raphael Setin Nov 08 '21 at 22:27
  • @RaphaelSetin As I have understood so far, it is possible for Docker desktop on Windows , can it be done also on Docker for Mac? – Homa Jan 21 '22 at 11:11
  • 1
    @HomaPourMohammadi this is not possible in a MacOS, but there are workarounds which involve more work, like [this](https://stackoverflow.com/questions/54650721/can-i-run-windows-containers-on-docker-desktop-for-mac/68908748#68908748). – Raphael Setin Feb 04 '22 at 06:07
  • 1
    For some reason, the "Switch to Windows containers..." option wasn't visible, so I ran a `C:\Program Files\Docker\Docker\DockerCLI.exe -SwitchDaemon` command instead as described [here](https://stackoverflow.com/a/67007851/2047725) – w5m Jun 15 '22 at 13:59
  • Also you might have to enable windows containers using: Enable-WindowsOptionalFeature -Online -FeatureName $("Microsoft-Hyper-V", "Containers") -All – cpoDesign Dec 07 '22 at 17:09
77

Providing the platform in the Docker file on M1 fixed it for me.

E.g., FROM --platform=linux/amd64 amazonlinux:2018.03

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Manish
  • 1,452
  • 15
  • 25
  • 3
    This worked for me!, I'm running this image on a mac M1 and i had to update the Dockerfile to this `FROM --platform=linux/amd64 maven:3.6-jdk-8-slim` – Joselo Jun 29 '22 at 14:55
  • Worked here too. Im using M1 Monterey with amazoncorretto:17-alpine-jdk image – Gabriel Silva Jul 30 '22 at 06:09
  • The native platform appears to be linux/arm64/v8, so if your container can use it, you can use `FROM --platform=linux/arm64/v8 ...` – samkass Sep 02 '22 at 23:56
  • I'm on windows and this worked for me. I was having the following error : `failed to create LLB definition: no match for platform in manifest sha256:37bfa5a2240dcd178564aa9ee041ae2c88dde18c662c2c7ddc965e26724a81bb: not found` With a docker file of one line : `FROM mcr.microsoft.com/windows/server:ltsc2022`. I transformed it to this `FROM --platform=windows/amd64 mcr.microsoft.com/windows/server:ltsc2022` and I was able to build (At least start donwload) – El Bachir Apr 11 '23 at 12:13
  • Why does this work? – michaelsnowden Jul 05 '23 at 02:35
47

In my case, I was using a Mac with an M1 processor to run a Python image. My docker-compose and Dockerfile looked like this:

docker-compose.yml

version: '3.7'

services:
  words_bot:
    build: .
    restart: unless-stopped

Dockerfile:

FROM python:3-onbuild
COPY . /usr/src/app
CMD ["python", "-m", "bot"]

It seems like the image was expecting an x86 host architecture, so I was getting the error the OP is referring to.

After I added platform: linux/amd64 into docker-compose.yml everything started working as expected:

version: '3.7'

services:
  cng_words_bot:
    build: .
    platform: linux/amd64
    restart: unless-stopped
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
konnovdev
  • 823
  • 8
  • 16
  • 2
    Awesome, You save my day! – Dhanu K Mar 22 '22 at 16:57
  • 1
    However this breaks the setup for a Linux environment. Would be nice to have a solution that could work everywhere – Jonny Apr 21 '22 at 08:58
  • @Jonny I haven't run into this problem on linux because my mac and linux server are both arm, if you want to use python on both architectures you can try a different (not onbuild) python image, or just build a python image yourself from ubuntu, here's an example (note: if you don't need all the ubuntu software then use alpine image of linux) FROM ubuntu:20.04 RUN apt-get update && apt-get install -y python3 python3-dev pip VOLUME /usr/src/app WORKDIR /usr/src/app COPY requirements.txt /usr/src/app RUN pip install -r requirements.txt CMD ["python", "-m", "bot"] – konnovdev May 14 '22 at 05:34
9

Docker gets confused with some architectures like the ARM architecture(M1 for instance). Make sure to specify the architecture (platform).

  services:
      service-name:
        platform: linux/x86_64. # Specify the architecture here
        image: some-image

Update:

If you're using an Apple Silicon Chip machine (arm architecture), you shall activate on you Docker Desktop the following features for better virtualization:

  • Use Virtualization framework
  • Use Rosetta for x86/amd64 emulation on Apple Silicon

It will use the Rosetta 2 emulator instead of the qemu one, The difference is just outstanding.

Shady Smaoui
  • 867
  • 9
  • 11
4

(Assuming you are running Docker on a Windows platform) To resolve this issue, switch the container from Linux to Windows by right clicking on the Docker icon in the tray (we see this icon near the system clock after starting the Docker Engine) and select the option "Switch to Windows containers..."

Step 1

Step 1

Step 2

Step 2

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
shary.sharath
  • 649
  • 2
  • 14
  • 29
3

For me, the Docker image itself was not building. So I had to add --platform linux/x86_64 as parameter for docker build command.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rakesh
  • 135
  • 3
  • 15
2

I just stumbled over a similar issue myself when using Docker build on a very simple Dockerfile:

FROM node:lts-alpine

COPY ./ /app/
RUN cd /app && npm ci && npm run build

When running docker build -t foo ., the OP's error with a slightly different cause came up.

However, when running docker pull node:lts-alpine first, then repeating that build command, the build was running just fine.

IMHO, this looks like a hiccup in Docker for Windows. Switching to Windows containers didn't seem like a reasonable option here for the base container is pretty valid for a Linux-based context. I tried to switch anyway, but that was bringing up a different error of Docker for Windows, only.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Thomas Urban
  • 4,649
  • 26
  • 32
0

On macOS with an Intel chip, building a "standard" Docker image, I ran into this.

Restarting the Docker daemon fixed it for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Chris
  • 4,425
  • 5
  • 34
  • 49
0

In my case. I was using a Mac M1, and it was missing a /, like the following:

How it was:

version: '3.6'
services:
  service-name:
    build:
      # It was without the /, like:
      context: .

Fixed:

version: '3.6'
services:
  service-name:
    build:
      # The correct one
      context: ./

The error was:

failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to create LLB definition: unexpected status code [manifests latest]: 401 Unauthorized

And also I needed to change the credsStore value. More information: docker pull gives error: no basic auth credentials #207

I hope that it helps someone, I spent a lot of time to get it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lerox
  • 5
  • 2
0

Searching for a Docker image tag that works for your hardware architecture fixes it. For instance, if you are using Apple silicon (M1 or M2), the architecture is arm64.

See image

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
biniam
  • 8,099
  • 9
  • 49
  • 58
0

In my case I was simply disconnected from the wifi, so double-check that you're online before spending hours trying to debug the issue!

half of a glazier
  • 1,864
  • 2
  • 15
  • 45