images icon indicating copy to clipboard operation
images copied to clipboard

Mac M1 - Ubuntu image not running under ARM architecture

Open marcusschiesser opened this issue 2 years ago • 12 comments

How can the ubuntu image be run on Mac M1 on ARM architecture?

I am using the following setup:

  • Mac M1 with MacOS 13.0.1
  • Docker Desktop 4.16.2 with Rosetta enabled
  • Visual Studio Code 1.17.3

Using the devcontainer.json below, processes are running on x86 arch as uname shows:

# uname -m
x86_64

How can the devcontainer run on ARM?

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/devcontainers/images/tree/main/src/base-ubuntu
{
  "name": "Ubuntu",
  "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
  // Set *default* container specific settings.json values on container create.
  "settings": {
    "python.defaultInterpreterPath": "/usr/local/bin/python",
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
    "python.formatting.blackPath": "/usr/local/py-utils/bin/black",
    "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
    "python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
    "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
    "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
    "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
    "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
    "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
  },
  // Add the IDs of extensions you want installed when the container is created.
  "extensions": [
    "ms-python.python",
    "ms-python.vscode-pylance",
    "ms-azuretools.vscode-docker",
    "Splunk.splunk",
    "esbenp.prettier-vscode",
    "dbaeumer.vscode-eslint",
    "steoates.autoimport",
    "mgmcdermott.vscode-language-babel",
    "streetsidesoftware.code-spell-checker",
    "shivanshu-gupta.scratchpads",
    "thenuprojectcontributors.vscode-nushell-lang"
  ],
  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  // "forwardPorts": [],
  // Use 'postCreateCommand' to run commands after the container is created.
  // "postCreateCommand": "pip3 install --user -r requirements.txt",
  // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
  "remoteUser": "vscode",
  "remoteEnv": {
    "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
  },
  "features": {
    "ghcr.io/devcontainers/features/docker-outside-of-docker:1": "latest",
    "ghcr.io/devcontainers/features/node:1": {
      "version": "16"
    },
    "ghcr.io/devcontainers/features/python:1": {
      "version": "3.7"
    }
  }
}

marcusschiesser avatar Feb 06 '23 09:02 marcusschiesser

Hi 👋

Have you tried using the Dev Containers Extension to open this in a container?

Nit: The settings & extensions should be within customizations.vscode object. Sample here

samruddhikhandale avatar Feb 09 '23 23:02 samruddhikhandale

@samruddhikhandale yes, I used the Dev Containers Extension to open this in a container - Is there any other way of doing it?

marcusschiesser avatar Feb 10 '23 03:02 marcusschiesser

I was double checking if you are using the extension or working in a Codespace.

The ubuntu image is built for multi-arch/multi-platform support and supports arm.

I tried to reproduce with your dev config, architecture looks good to me 👇

  • Mac M1 Max with MacOS 13.0.1
  • Docker Desktop 4.16.2
  • Visual Studio Code 1.75.1

image

@chrmarti are you aware why the user might be seeing x86_64 instead of aarch64 or arm64 ?

samruddhikhandale avatar Feb 10 '23 17:02 samruddhikhandale

@samruddhikhandale did you enable Rosetta? I remember having the same issue with qemu, but definitely have it now using Rosetta.

marcusschiesser avatar Feb 13 '23 04:02 marcusschiesser

I was able to randomly reproduce this with 👇 devcontainer.json

{
	"name": "Ubuntu",
	"image": "mcr.microsoft.com/devcontainers/base:ubuntu"
}

image

If you look at the devcontainer-info result, then the image looks cached and is very old. Removing the image from my local cache and rebuilding the container (without cache) fixed it for me.

image

@marcusschiesser Can you try that?

samruddhikhandale avatar Feb 14 '23 22:02 samruddhikhandale

@samruddhikhandale did you enable Rosetta? I remember having the same issue with qemu, but definitely have it now using Rosetta.

I still don't have Rosetta enabled but was able to reproduce this issue. Thus, Rosetta might not be the root cause for this issue 🤔

samruddhikhandale avatar Feb 14 '23 22:02 samruddhikhandale

@samruddhikhandale Hmm, that's interesting. I just did what you said (Removing the image from the local cache and rebuilding the container), and I still get x86 with the latest image:

image

marcusschiesser avatar Feb 15 '23 04:02 marcusschiesser

That's the VS that I am using: image

marcusschiesser avatar Feb 15 '23 04:02 marcusschiesser

Can't upgrade to 1.75.x because of https://github.com/microsoft/vscode-remote-release/issues/7974

marcusschiesser avatar Feb 15 '23 04:02 marcusschiesser

I'm also hitting this issue. I worked around it by changing the base image to ubuntu:latest instead of the microsoft-released one, but the VSCode extension hard-codes the ghcr.io/devcontainers/templates/docker-existing-docker-compose:latest image (which doesn't support aarch64, only x86_64), and there's no way to change it that I can tell.

[1862535 ms] Start: Run: docker version --format {{.Server.APIVersion}}
[1863118 ms] 1.43
[1880056 ms] No dev container config found. Additional locations checked:
- /Users/jyn/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/node_modules/vscode-dev-containers/repository-containers/github.com/redjack/sensor/.devcontainer/devcontainer.json
[1888802 ms] Start: Run: /private/var/folders/0c/cvw1ywdj5c3b73kt13g4svyw0000gr/T/AppTranslocation/823B01AE-DA24-406C-808C-4F26ABDFD158/d/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node /Users/jyn/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js templates apply --workspace-folder /var/folders/0c/cvw1ywdj5c3b73kt13g4svyw0000gr/T/tmp-output-dir-1691508367826 --template-id ghcr.io/devcontainers/templates/docker-existing-docker-compose:latest --template-args {} --features [] --tmp-dir /var/folders/0c/cvw1ywdj5c3b73kt13g4svyw0000gr/T/tmp-dir-1691508367826
[1888980 ms] [2023-08-08T15:26:08.005Z] @devcontainers/cli 0.25.2. Node.js v16.14.2. darwin 22.6.0 arm64.
[1889216 ms] [2023-08-08T15:26:08.242Z] HTTP request failed with status code 403: : Forbidden
[1889217 ms] [2023-08-08T15:26:08.243Z] Failed to get registry auth token with error: Error: HTTP 403: Forbidden
[1889357 ms] [2023-08-08T15:26:08.382Z] Failed to fetch template manifest for ghcr.io/devcontainers/templates/docker-existing-docker-compose:latest
[1889357 ms] [2023-08-08T15:26:08.382Z] Failed to fetch template 'ghcr.io/devcontainers/templates/docker-existing-docker-compose:latest'.
[1889360 ms] Exit code 1

Using a dockerfile instead of a docker-compose file shows a similar error:

[2314012 ms] [2023-08-08T15:33:13.038Z] Failed to get registry auth token with error: Error: HTTP 403: Forbidden
[2314151 ms] [2023-08-08T15:33:13.177Z] Failed to fetch template manifest for ghcr.io/devcontainers/templates/docker-existing-dockerfile:latest

jyn514 avatar Aug 08 '23 15:08 jyn514

[2314012 ms] [2023-08-08T15:33:13.038Z] Failed to get registry auth token with error: Error: HTTP 403: Forbidden [2314151 ms] [2023-08-08T15:33:13.177Z] Failed to fetch template manifest for ghcr.io/devcontainers/templates/docker-existing-dockerfile:latest

LONCHHAIHONG avatar Sep 06 '23 07:09 LONCHHAIHONG

[1862535 ms] Start: Run: docker version --format {{.Server.APIVersion}} [1863118 ms] 1.43 [1880056 ms] No dev container config found. Additional locations checked:

  • /Users/jyn/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/node_modules/vscode-dev-containers/repository-containers/github.com/redjack/sensor/.devcontainer/devcontainer.json [1888802 ms] Start: Run: /private/var/folders/0c/cvw1ywdj5c3b73kt13g4svyw0000gr/T/AppTranslocation/823B01AE-DA24-406C-808C-4F26ABDFD158/d/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node /Users/jyn/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js templates apply --workspace-folder /var/folders/0c/cvw1ywdj5c3b73kt13g4svyw0000gr/T/tmp-output-dir-1691508367826 --template-id ghcr.io/devcontainers/templates/docker-existing-docker-compose:latest --template-args {} --features [] --tmp-dir /var/folders/0c/cvw1ywdj5c3b73kt13g4svyw0000gr/T/tmp-dir-1691508367826 [1888980 ms] [2023-08-08T15:26:08.005Z] @devcontainers/cli 0.25.2. Node.js v16.14.2. darwin 22.6.0 arm64. [1889216 ms] [2023-08-08T15:26:08.242Z] HTTP request failed with status code 403: : Forbidden [1889217 ms] [2023-08-08T15:26:08.243Z] Failed to get registry auth token with error: Error: HTTP 403: Forbidden [1889357 ms] [2023-08-08T15:26:08.382Z] Failed to fetch template manifest for ghcr.io/devcontainers/templates/docker-existing-docker-compose:latest [1889357 ms] [2023-08-08T15:26:08.382Z] Failed to fetch template 'ghcr.io/devcontainers/templates/docker-existing-docker-compose:latest'. [1889360 ms] Exit code 1

LONCHHAIHONG avatar Sep 06 '23 07:09 LONCHHAIHONG