Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify architecture (platform) flag for Docker images in VS Code Dev Containers?

When I pull a Docker image locally through the command line, I can use the --platform flag (as explained in the docs) to pull an image for an architecture different from the one I'm running Docker on. For instance, I can pull an image for linux/amd64 even though I am running Docker on Darwin/arm64.

Docker desktop is capable of running images for some different architectures using a VM. On macOS for Apple Silicon it does so using QEMU.

When I configure a Dev Container for VS Code, I can specify a Docker image with a particular tag in devcontainer.json, but how can I specify the platform/architecture? I can't find any configuration option in the docs for devcontainer.json.

like image 287
Gabriel C Avatar asked Oct 15 '25 09:10

Gabriel C


1 Answers

While there is no direct way to specify platform architecture within the .devcontainers.json file, you can use the dockerCompose route to achieve your goal. This can be achieved by modifying your config file as below.

"dockerComposeFile": "docker-compose.yml",
"service": "<service-name> in docker-compose file",
"workspaceFolder": "<volume mount> in service",
// "build": {
//  "dockerfile": "Dockerfile",
// },

then create a docker-compose.yml file within the .devcontainers folder similar to

version: '3.8'

services:
 wta-api:
   build: Dockerfile
   platform: linux/amd64
   ports:
    - 8000:8000 // modify as required
   volumes:
    - ../codebase:/workspace directory

You can learn more from the documentation here

UPDATE 1: From my experience, it appears that devcontainers uses amd64 by default on Apple Silicon

UPDATE 2: It appears VSCode forces the platform of the container to match the platform of the docker vm, so the only way I was able to achieve this was to create an X86_64 container environment on M1, for more info on Colima, see here

like image 172
Mubarak Imam Avatar answered Oct 17 '25 20:10

Mubarak Imam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!