visual studio code - Problem with corrupted characters whle trying to attach to a running docker container using vscode cli - St

admin2025-04-26  3

For a project I'm building a bash script to create a development environment using Docker and VsCode. For the part that attaches the vscode to the running container, I found this script that worked for some people:

code --folder-uri "vscode-remote://attached-container+my_container" --verbose

The bash response:

12:46:48 [mohammadreza@Z500] ~/ $ code --folder-uri "vscode-remote://attached-container+my_container" --verbose
Fontconfig error: "/home/mohammadreza/.config/fontconfig/fonts.conf", line 1: XML declaration allowed only at the start of the document
[main 2025-01-14T09:40:00.842Z] [File Watcher (node.js)] Request to start watching: /home/mohammadreza/.config/Code/User (excludes: <none>, includes: <all>, filter: <none>, correlationId: <none>),/home/mohammadreza/.config/Code/User/settings.json (excludes: <none>, includes: <all>, filter: <none>, correlationId: <none>)
[main 2025-01-14T09:40:00.857Z] Sending env to running instance...
[main 2025-01-14T09:40:00.860Z] [File Watcher (node.js)] Started watching: '/home/mohammadreza/.config/Code/User'
[main 2025-01-14T09:40:00.860Z] [File Watcher (node.js)] Started watching: '/home/mohammadreza/.config/Code/User/settings.json'
[main 2025-01-14T09:40:00.914Z] Sent env to running instance. Terminating...
[main 2025-01-14T09:40:00.915Z] Lifecycle#kill()
[main 2025-01-14T09:40:00.915Z] Lifecycle#onWillShutdown.fire()

but I get the following error when executing it:the vscode error Dev Containers extension's logs indicating that the container name characters get corrupted.

I tried following alternative syntax:

code --folder-uri="vscode-remote://attached-container+my_container"
code --folder-uri vscode-remote://attached-container+my_container
code --folder-uri=vscode-remote://attached-container+my_container
code --folder-uri "vscode-remote://attached-container+91d1f2a7f1ce46ed3c2423d5de3914a264d403d03d8f43541a22c922bd5a8150"
code --folder-uri "vscode-remote://attached-container+91d1f2a7f1ce"

Which in all above cases characters get corrupted

Also I made sure of container name being correct by executing following commands:

docker inspect my_container
docker ps

Also I tried to manually execute a command in container using VsCode Terminal:

docker exec -it 91d1f2a7f1ce /bin/bash

And all of above worked just fine.

转载请注明原文地址:http://anycun.com/QandA/1745599244a90997.html