I want to use a command line tool to attach a remote container. I tried this command (see below), but it's of no use. Does anyone know the correct command?
code --folder-uri vscode-remote://dev-container+4aaf623ee98a52fa311226a2c619be19addfa221c090b9a3bc37e7cba03a7fce/easycv
To automate this, I created this cross-plattform-ish solution:
https://github.com/geircode/vscode-attach-to-container-script
This solution creates the hex based on the name of the running container.
Windows CMD script:
docker run --rm geircode/string_to_hex bash string_to_hex.bash "<container_name>" > vscode_remote_hex.txt
set /p vscode_remote_hex=<vscode_remote_hex.txt
code --folder-uri=vscode-remote://attached-container+%vscode_remote_hex%/app
That string of characters after dev-container+ is an ascii path to your dev container folder encoded in hexadecimal.
To open a folder in a container you can use the following style command:
code --folder-uri=vscode-remote://dev-container%2B{path-in-hex}/{path-inside-container}
For example to open the folder /workspaces/test in the development container located in /Users/jkells/projects/vscode-devcontainer I use the following CLI command.
code --folder-uri=vscode-remote://dev-container%2B2f55736572732f6a6b656c6c732f70726f6a656374732f7673636f64652d646576636f6e7461696e6572/workspaces/test
To convert the string /Users/jkells/projects/vscode-devcontainer into the hexadecimal 2f55736572732f6a6b656c6c732f70726f6a656374732f7673636f64652d646576636f6e7461696e6572 you can use the following command
printf /Users/jkells/projects/vscode-devcontainer | od -A n -t x1 | tr -d '[\n\t ]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With