I've started a docker-container on a linux server. Then created a user inside of it, after which I can login as that user using docker exec -it -u $(HOST_USER_NAME) <docker-container name> bash
, which works fine. But now I want to debug my python code running inside the container and for that I am using Dev-Container extension to attach to the container. However, the issue is that Dev-Container always logs in as the root, and then doesn't have access to certain files that only the $(HOST_USER_NAME) have access to. So is there a way I can tell dev-container to login as the $(HOST_USER_NAME). Sorry, if this is trivial, it's my first week with docker.
I tried https://github.com/microsoft/vscode-remote-release/issues/1477, which says to use docker run -u. But, the way our system is setup is that it uses docker-compose up to run the container using a docker-compose.yml file.
I also tried specifying the user
in the docker-compose.yml, but at the time of running docker compose-up
. But it rightly says no such user is available, because user is later created using docker exec
inside the running container
Finally, I also thought of changing user after attaching to the container using the dev-container, but then I get following errors while running the vscode debugger:
/opt/venv/bin/python: can't open file '/root/.vscode-server/extensions/ms-python.python-2023.12.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher': [Errno 13] Permission denied
Found it, simply after logging into vscode container or the main server, press F1 and search
Open attached container configuration file.
update the respective configuration file to add remoteUser field as:
{
"workspaceFolder": "..............",
"remoteUser": "....",
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
"ms-toolsai.jupyter-renderers",
"ms-toolsai.vscode-jupyter-cell-tags",
"ms-toolsai.vscode-jupyter-slideshow"
]
}