allow exec command after --workspace-folder flag
It seems that the 'exec' command is only allowed as the first parameter.
devcontainer --workspace-folder . exec ls
OCI runtime exec failed: exec failed: unable to start container process: exec: "exec": executable file not found in $PATH: unknown
Like up etc., it expects options followed by exec to be allowed.
With this change, one can create an alias as alias devc="devcontainer --workspace-folder PATH".
Hi @n-arakawa,
Thank you for reaching out!
Could you kindly clarify what you are attempting to achieve with the exec option? Typically, the exec command is used to execute commands inside a running a container, and it is independent of the --workspace-folder flag. It requires a valid container ID to initiate the command.
devcontainer exec
Please let me know if this helps resolve your issue. If not, feel free to share more details, and I’ll be happy to assist further.
Thanks, Sireesha
Hi Sireesha
My team uses devcontainer in the same docker environment. This means that multiple docker containers run simultaneously for a single development container definition, and as a result fixed container names cannot be used.
For this reason, I prefer devcontainer exec to decker exec, which requires looking up an auto-generated docker name.
Another option is to add a metadata retrieval command such as devconteiner get-metadata docker-name.
Thanks,
Hi @n-arakawa,
The container name may not always be unique if you manually assign one. However, when using DevContainers, Docker automatically generates a unique name for the container, and the container ID is always guaranteed to be unique.
You can use the devcontainer up command to start the container. For more details, feel free to check here.
To access a specific container and execute commands, you’ll need to provide the container ID, which is necessary when using docker exec to ensure you're targeting the correct container.
If you have any further questions or need assistance, don’t hesitate to reach out. We’re happy to help!
Best regards, Sireesha
Hi Sireesha
As you say, the docker ID and name are dynamically generated.
when using DevContainers, Docker automatically generates a unique name for the container,
So to use the docker exec command, one need to find the ID or name yourself.
This is why I prefer devcontainer exec over docker exec.
Thank you in advance
Hello @n-arakawa, Apologies for the delayed response. I’m not entirely sure I fully understand the issue — could you please clarify a bit? I hope things are working smoothly now. If you're still exploring options, here's the README that clearly explains how to use the devcontainer exec command — feel free to adapt it to your workflow.
For example, you can run:
devcontainer exec --workspace-folder
Thanks, Sireesha