Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start devcontainer (up) from already built image #803

Open
sevetseh28 opened this issue Apr 17, 2024 · 4 comments
Open

Start devcontainer (up) from already built image #803

sevetseh28 opened this issue Apr 17, 2024 · 4 comments

Comments

@sevetseh28
Copy link

sevetseh28 commented Apr 17, 2024

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

@samruddhikhandale
Copy link
Member

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--features and vsc-workspace--features-uid) are created by the up command when it builds an image from a Dockerfile. If you use a prebuilt image, these images will not be created.

@sevetseh28
Copy link
Author

sevetseh28 commented Apr 18, 2024

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!

@kylemcmearty
Copy link

kylemcmearty commented Jun 20, 2024

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.

@simon376
Copy link

did you find any solution to this? it's really unintuitive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants