-
Notifications
You must be signed in to change notification settings - Fork 293
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
devcontainer.json property to execute a command whenever VS Code starts a container #2772
Comments
Make sense. Note that in general you can connect with multiple windows to the same container. Would you want the command to be run only once (when starting the VS Code Server) or for each connection? |
It would be once per container start, so as we were discussing in MicrosoftDocs/vsonline#403, perhaps I have a concrete example of where it would be useful in an improved I'll queue up a PR on it so you can see what I'm talking about. |
@chrmarti Actually, I can just point you to the README in the branch which explains what needs to happen. I'd rather drop the use of the ENTRYPOINT in favor of this property. |
Another related request. Have this also apply to non devcontainers. For example, I'd like to have a setting that ran a command every time I attached to a running container. My workflow right now has me connecting to containers created by another process, or kubernetes containers, and I'd like to be able to connect to a container, and have some commands run automatically. My plan right now was to use this extension but a built in feature would be better. |
Will add
The only case where Remote-Containers deletes a container automatically is when rebuilding the container. Should it run the The user can delete a container through the Remote Explorer. Should the What if the user deletes the container through the Docker extension or some other tool or the Docker CLI? Is not running the configured command in this case good enough? |
The full list of Docker engine events is described in Docker spec and gives no space for discussion. It's too late Docker events |
@PavelSosin-320 The extension does not run at all times (neither does VS Code), so we cannot catch all Docker events. These commands need to run at specific stages during the startup of the devcontainer, so invoking the commands from the extension's startup code seems appropriate. |
Related to https://github.com/MicrosoftDocs/vsonline/issues/403
Most Docker images do not have a functional daemon system which makes starting things that need to run whenever a container is started difficult. Typically this is solved by using a custom ENTRYPOINT or CMD in a Dockerfile.
However, if you need to start something that is part of your application or a development dependency (e.g. a database or a file watcher), you may not want or be able to override the default ENTRYPOINT or CMD since it depends on scripts in the source tree actually being present. Furthermore, by default, the command and entrypoint are both overridden by VS Code in the Dockerfile case. In some cases applying a
.bashrc
script is enough, but this does not work in situations where sh, ash (Alpine default), or dash (Ubuntu) are used since they have no concept of an rc file.As suggested in https://github.com/MicrosoftDocs/vsonline/issues/403, something like a
postAttachCommand
(oronResumeCommand
as proposed there) would allow developers to resolve this situation withdevcontainer.json
for both Dockerfile and Docker Compose scenarios, along with any attach configs.//cc: @chrmarti @egamma
The text was updated successfully, but these errors were encountered: