I'm trying to run python code from docker using Visual Studio Code extension Remote Container. Here is the Dockerfile:
FROM python:3.8-slim-buster
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED 1
ENV BLOB_CONTAINER_SAS_CONNECTION="secret"
ENV ROUND_LEVEL="0"
# Install pip requirements
ADD requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
COPY [ ".env", "/app"]
ADD /src/sample_code_round_data_docker.py /app
# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
ARG USERNAME=someuser
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
#
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
# [Optional] Set the default user. Omit if you want to keep the default as root.
USER $USERNAME
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "sample_code_round_data_docker.py"]
And here is .devcontainer.json:
{
"name": "Existing Dockerfile",
"context": "..",
"dockerFile": "Dockerfile",
"settings": {
"terminal.integrated.shell.linux": null
},
"extensions": [],
"remoteUser": "someuser"
}
When i run it, it throws an error:
Shell server terminated (code: 126, signal: null)
unable to find user someuser: no matching entries in passwd file
When I search for the passwd
file inside container:
cat /etc/passwd
There is no user someuser
I had the same issue. For me I had forgotten to create my vscode user at first, so I modified my image to create the vscode user, but vscode did not update to use the new image.
I had to manually remove the (old) container vscode was trying to use. If you go to
Remote Containers: Show Logs
You can see the ID of the container VSCode is trying to use.
You can then kill and remove the container with:
docker kill $YOUR_ID_HERE
docker rm $YOUR_ID_HERE
Then tell vscode to try opening the project in a remote container again. It will be forced to create a new container using the updated image.
I was having this issue but there were actually 2 parts of this problem for me.
The first half was that I was basing some of my configurations from the vscode sample remote containers including the following line in my devcontainer.json:
// Comment out this line to run as root instead.
"remoteUser": "vscode"
But I was also trying to use one of my own docker images, so the user vscode
didn't exist in my docker image. If you just comment the configuration line out or just switch it to a user you know exists (i.e maybe root
), then that will solve things assuming you are starting from a clean or new container.
The second half was, like Increasingly Idiotic
had stated, that you may need to close/remove the old container as it maybe saving your prior username, even if you already have updated your devcontainer.json file. Thus rebuilding will fail even with an updated remoteUser
value.
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