cli icon indicating copy to clipboard operation
cli copied to clipboard

Add `-w, --workdir` flag support to `devcontainer exec`

Open groner opened this issue 1 year ago • 3 comments

Currently devcontainer exec always runs commands from the workspace folder.

I would like to be able to devcontainer exec from a subdirectory of my devcontainer project.

The proposal is for devcontainer exec to accept and pass the -w or --workdir flags to docker compose exec or docker exec.

groner avatar Dec 08 '23 16:12 groner

Thank you for the feature request Could you please also suggest the use case that can benefit from this feature? That may help to weigh the priority.

@chrisdias what do you think?

eljog avatar Dec 12 '23 02:12 eljog

Much of my work is done outside of the devcontainer, but I need to be able to run some commands in the devcontainer. For this I use devcontainer exec, but I need a way to tell it where to run the command from when I'm not working in the workspace folder root.

Ideally I would like devcontainer exec to be able to map my current working directory to the equivalent subdirectory of the workspace folder in the devcontainer.

For now I use the following script to achieve this, but I believe devcontainer-cli would be more useful if it did this itself.

# NOTE: The feature request above suggests the path on the host should be
# mapped to the path in the container. This script uses $PWD directly without
# translation because my devcontainers mount the workspace folder in the
# container to the path of the workspace folder on the host.
devcontainer exec --workspace-folder="$PROJECT_ROOT" \
  bash -ec '
    cd "$1"; shift
    exec -- "$@"
    ' \
  bash \
  "$PWD" \
  "$@"

groner avatar Dec 29 '23 17:12 groner

We really need that feature, because we are using many (legacy) scripts inside the devcontainer which only work with the correct working directory.

At the moment we build our own workaround, but it's really unstable and not pretty.

tobikuch avatar Feb 26 '24 12:02 tobikuch