cli
cli copied to clipboard
Start devcontainer (up) from already built image
Hi, im a bit confused on how to spin up a devcontainer from an already prebuilt image.
I see no options to the up
command to specify an image name. But I see that we have a dedicated build
command. What is the use of it then?
The up command seems to create two images regardless:
-
vsc-workspace-<id>-features
-
vsc-workspace-<id>-features-uid
My goal is to build first and then just use up to reuse that previously built image without having the up
command creating new tags or building new things, just running the container. Is this possible with the current CLI ?
Thank you
Hello 👋
Yes, it's possible to use a prebuilt image with the devcontainer CLI. The build
command is used to build an image from a Dockerfile. If you already have a prebuilt image, you don't need to use the build
command.
The up
command is used to create and start a container from an image. If you don't specify an image, it will build one from the Dockerfile in your .devcontainer directory. If you want to use a prebuilt image, you can specify it in the devcontainer.json
file.
Refer to https://containers.dev/guide/prebuild for more information, thanks!
The two images you're seeing (vsc-workspace-up
command when it builds an image from a Dockerfile. If you use a prebuilt image, these images will not be created.
Thank you for the prompt response!
I have observed that even without specifying a Dockerfile and only defining a base image in the devcontainer.json, the up command still processes further, adding layers and building a new image. This might not be the case with all devcontainer.json configurations, but it is happening in my specific scenario.
As an example, here’s what’s occurring:
- When I execute the up command, I receive an image ID of 123.
- When I run the build command separately, the resulting image ID is 789.
The issue is that I do not receive identical images from these two commands.
My objective is to avoid modifying the devcontainer.json, as suggested by the documentation. Instead, I want the up
command to simply start the container without initiating the build process, by leveraging an already-built image.
It seems my only viable option is to use the up command initially to build the image, push this image to a registry, and then pull from the registry for subsequent uses of the up command. Is this understanding correct?
Ultimately, I want to ensure the devcontainer.json remains unchanged while also avoiding any additional layer builds when running the up command.
Thank you again for your assistance!
I'm looking for a similar solution
My objective is to avoid modifying the devcontainer.json, as suggested by the documentation. Instead, I want the up command to simply start the container without initiating the build process, by leveraging an already-built image.
I already have a devcontainer image built and I want to start / run the container from a script.
did you find any solution to this? it's really unintuitive