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 Overflowvisual studio code - How can I use a local image using vscode-devcontainer - Stack Overflow
docker - vscode devcontainers - why are two images built? - Stack Overflow
How to Creating Dev Container from docker image in private registry?
docker - DevContainer attatch to new image container in vscode? - Stack Overflow
Videos
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.
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:
- Have the image you want already in your docker local image cache (shows up with the exact same name in
docker image lsresults) - Use the identical matching name in your
devcontainer.jsonfor the"image"field.
I'm having a hard time finding instructions on creating a dev container from an existing image. At my employers, we have a private registry, say at docker.internal.domain where the image sits. Let's say the image is "docker.internal.domain/devops-utilties:latest"
I want to use that image as a base for my dev container, installing VS code extensions into it for linting and running tests.
But I can only find instructions for using predefined images . Are the any templates or examples I can use to make a dev container.json and related files needed to build and run a dev container image?
I'd like to do this as some linters like ansible-lint are throwing errors since the path to files like ansible.cfg or the vault password file are different outside the container then inside the container. If I can have the linters running inside the container, problem solved!
Note: I'm a complete noob at this , so if there is a better way, I'm open to hear it!
Do note that the way the utilities container works is you run a wrapper script that sets up environment variable, then executes docker compose run -rm service-name to start the container, which opens an interactive shell for the user to execute command line utilities from.