cli icon indicating copy to clipboard operation
cli copied to clipboard

allow exec command after --workspace-folder flag

Open n-arakawa opened this issue 6 months ago • 5 comments

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".

n-arakawa avatar Jul 16 '25 00:07 n-arakawa

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

sireeshajonnalagadda avatar Sep 02 '25 08:09 sireeshajonnalagadda

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,

n-arakawa avatar Sep 02 '25 22:09 n-arakawa

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

sireeshajonnalagadda avatar Sep 05 '25 06:09 sireeshajonnalagadda

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

n-arakawa avatar Sep 06 '25 04:09 n-arakawa

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 cargo run

Thanks, Sireesha

sireeshajonnalagadda avatar Oct 30 '25 06:10 sireeshajonnalagadda