I got the same issue before.

To solve this problem, you should use F1 > Dev Containers: Rebuild Container rather than F1 > Dev Containers: Rebuild Container Without Cache.

Then it should be able to use a local image. Tested on my local and worked fine.

Answer from Zac on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › devcontainers › create-dev-container
Create a Dev Container
November 3, 2021 - An image is like a mini-disk drive with various tools and an operating system pre-installed. You can pull images from a container registry, which is a collection of repositories that store images.
🌐
Development Containers
containers.dev › implementors › json_reference
Dev Container metadata reference
The devcontainer.json file contains any needed metadata and settings required to configure a development container for a given well-defined tool and runtime stack. It can be used by tools and services that support the dev container spec to create a development environment that contains one ...
🌐
Visual Studio Code
code.visualstudio.com › docs › devcontainers › containers
Developing inside a Container
November 3, 2021 - You can also create a devcontainer.json by hand and use any image, Dockerfile, or set of Docker Compose files as a starting point.
🌐
GitHub
github.com › devcontainers › images
GitHub - devcontainers/images: Repository for pre-built dev container images published under mcr.microsoft.com/devcontainers · GitHub
At its simplest, all you need is a .devcontainer/devcontainer.json file in your project that references an image, Dockerfile, or docker-compose.yml, and a few properties.
Starred by 2K users
Forked by 908 users
Languages   Shell 46.3% | JavaScript 43.1% | Dockerfile 7.7% | Java 1.0% | Python 0.7% | C# 0.3%
Top answer
1 of 2
1

I got the same issue before.

To solve this problem, you should use F1 > Dev Containers: Rebuild Container rather than F1 > Dev Containers: Rebuild Container Without Cache.

Then it should be able to use a local image. Tested on my local and worked fine.

2 of 2
-1

Your specific error is:

=> ERROR [internal] load metadata for docker.io/library/demo:f  1.4s
[...]
ERROR: failed to solve: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

You don't actually have a demo:focal image in your docker local image cache is what this means, you probably named it something slightly different.


VSCode just uses docker (based on your VSCode settings configuration apparently) to implicitly build an image here, so it's temporarily constructing a Dockerfile that starts with FROM ${image} and then passing it to docker buildx build.

What you're seeing is docker checking the local image cache for demo:focal, not finding an image with that exact name and version, using the fallback behavior for image names that don't start with a URL+path and adding the default docker.io/library/ to the name, still not finding docker.io/library/demo:focal in the local image cache, and then trying to get the image from the registry since it's missing from the local image cache. Since your image name didn't have a registry URL, which is required to be able to pull, it uses the built-in fallback behavior and adds docker.io/library/ and then tries to pull from docker.io/library/demo:focal.

Apparently the docker.io registry is returning an "access denied" error if you try to do a docker pull docker.io/library/demo:focal.

So to fix this, you need to:

  1. Have the image you want already in your docker local image cache (shows up with the exact same name in docker image ls results)
  2. Use the identical matching name in your devcontainer.json for the "image" field.
🌐
Docker Hub
hub.docker.com › r › microsoft › vscode-devcontainers
microsoft/vscode-devcontainers - Docker Image
A link is available in the .devcontainer/devcontainer.json file added to your folder. Run Remote-Containers: Reopen in Container to use it locally, or Codespaces: Rebuild Container from within a codespace. See the Remote - Containers⁠ and GitHub Codespaces⁠ documentation for more information. You are also free to use these images on their own as you see fit.
🌐
GitHub
github.com › microsoft › vscode-dev-containers › blob › main › container-templates › image › .devcontainer › devcontainer.json
vscode-dev-containers/container-templates/image/.devcontainer/devcontainer.json at main · microsoft/vscode-dev-containers
November 30, 2023 - "image": "mcr.microsoft.com/vscode/devcontainers/base:debian-11", · // Set *default* container specific settings.json values on container create. "settings": {}, · // Add the IDs of extensions you want installed when the container is created. "extensions": [], ·
Author   microsoft
🌐
GitHub
docs.github.com › en › codespaces › setting-up-your-project-for-codespaces › adding-a-dev-container-configuration › introduction-to-dev-containers
Introduction to dev containers - GitHub Docs
As an alternative to using a Dockerfile you can use the image property in the devcontainer.json file to refer directly to an existing image you want to use. The image you specify here must be allowed by any organization image policy that has ...
Find elsewhere
🌐
DevPod
devpod.sh › devcontainer.json
devcontainer.json | DevPod docs | DevContainers everywhere
The primary file to configure your workspace is the devcontainer.json, that lives in the .devcontainer sub-folder of your project. This file includes information on what frameworks, tools, VS Code extensions and port-forwarding should be used during development. The file also usually references ...
🌐
GitHub
github.com › devcontainers › images › blob › main › src › javascript-node › .devcontainer › devcontainer.json
images/src/javascript-node/.devcontainer/devcontainer.json at main · devcontainers/images
Repository for pre-built dev container images published under mcr.microsoft.com/devcontainers - images/src/javascript-node/.devcontainer/devcontainer.json at main · devcontainers/images
Author   devcontainers
🌐
Development Containers
containers.dev › guide › dockerfile
Using Images, Dockerfiles, and Docker Compose
You can even add Dev Container settings and metadata right into the image itself. This avoids having to duplicate config and settings in multiple devcontainer.json files and keeps them in sync with your images!
🌐
GitHub
github.com › bamurtaugh › devcontainer-image-convert
GitHub - bamurtaugh/devcontainer-image-convert: VS Code extension to convert the devcontainer.json `image` property to a Dockerfile.
This is a simple Visual Studio Code extension to convert the "image" property in a devcontainer.json to a Dockerfile.
Starred by 3 users
Forked by 3 users
Languages   TypeScript 90.0% | JavaScript 10.0% | TypeScript 90.0% | JavaScript 10.0%
🌐
GitHub
github.com › devcontainers › spec › blob › main › docs › specs › devcontainerjson-reference.md
spec/docs/specs/devcontainerjson-reference.md at main · devcontainers/spec
The devcontainer.json file contains any needed metadata and settings required to configurate a development container for a given well-defined tool and runtime stack. It can be used by tools and services that support the dev container spec to ...
Author   devcontainers
🌐
Development Containers
containers.dev › implementors › json_schema
devcontainer.json schema
} }, "required": [ "dockerComposeFile", "service", "workspaceFolder" ] } }, "oneOf": [ { "allOf": [ { "oneOf": [ { "allOf": [ { "oneOf": [ { "$ref": "#/definitions/dockerfileContainer" }, { "$ref": "#/definitions/imageContainer" } ] }, { "$ref": "#/definitions/nonComposeBase" } ] }, { "$ref": "#/definitions/composeContainer" } ] }, { "$ref": "#/definitions/devContainerCommon" } ] }, { "type": "object", "$ref": "#/definitions/devContainerCommon", "additionalProperties": false } ] } { "allOf": [ { "$ref": "./devContainer.base.schema.json" }, { "$ref": "https://raw.githubusercontent.com/microsoft/vscode/main/extensions/configuration-editing/schemas/devContainer.codespaces.schema.json" }, { "$ref": "https://raw.githubusercontent.com/microsoft/vscode/main/extensions/configuration-editing/schemas/devContainer.vscode.schema.json" } ] }
🌐
Ben Selby
benmatselby.dev › post › vscode-dev-containers
Setting up a VS Code Dev Container · Ben Selby
March 21, 2021 - Once you have finished selecting your options, VS Code will open the devcontainer.json file, ready to edit. The Dockerfile is dropped into the .devcontainer folder within your project. If you have used the VS Code configuration screen, you’re likely to be using a base image provided by Microsoft.
🌐
GitHub
github.com › microsoft › vscode-dev-containers
GitHub - microsoft/vscode-dev-containers: NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own! · GitHub
November 30, 2023 - At its simplest, all you need is a .devcontainer/devcontainer.json file in your project that references an image, Dockerfile, or docker-compose.yml, and a few properties.
Starred by 4.7K users
Forked by 1.4K users
Languages   Shell 78.1% | Dockerfile 8.2% | JavaScript 7.0% | Jupyter Notebook 4.4% | Python 0.9% | C# 0.4%
🌐
Docker Hub
hub.docker.com › r › microsoft › devcontainers-base
microsoft/devcontainers-base - Docker Image
You can directly reference pre-built versions of Dockerfile by using the image property in .devcontainer/devcontainer.json or updating the FROM statement in your own Dockerfile to one of the following.
🌐
Bamurtaugh
bamurtaugh.github.io › dev-container-spec › implementors › json_reference
devcontainer.json reference
Today, devcontainer.json includes scenario specific properties for working without a container orchestrator (by directly referencing an image or Dockerfile) and for using Docker Compose as a simple multi-container orchestrator.