Reputation: 966
I start a Docker container with a special bash script that runs the container and then creates a user X with a dynamic name, UID and GUID in the container. I can then bash into the container and perform actions as this user X. The script also creates an 'alias' user named vscode with the same UID as the earlier created dynamic user X.
In VSCode I can attach to this container. Two questions:
The solution should be automated. Eg. manual intervention and committing the image as suggested below is possible but will make it much harder for users to just use my Docker image.
I updated to vscode 1.39 and tried to add:
ADD server-env-setup /root/.vscode-server/server-env-setup
But "server-env-setup" seems to be only used for WSL.
Upvotes: 2
Views: 2867
Reputation: 966
VSCode now implements a "remoteUser" property ehich you can set in the image configuration. This will ensure that VSCode logs into the container as the correct user.
Upvotes: 1
Reputation: 2156
I'll answer your questions in reverted order:
VSCode installs extensions after creating the container by using docker exec
command.
And now recipe: The easiest way is to take container already created by VSCode:
docker ps -a
. You should see last died containers something as:
docker commit a7aa5af7ec08 all-installed-vscode-image:latest
. Now you have a docker image with all your loved software installed. You can upload this image to your favorite docker registry and use also on other machines.docker run -i -u vscode all-installed-vscode-image:latest
. And attach vscode to this container. This is an answer to your first question.Also, you can review vscode documentation and use devcontainer.json configurations when you attach to already running containers and even containers running on remote machines.
Upvotes: 1