Python VS代码远程容器:外壳服务器终止(代码:126,信号:null)找不到用户xxx:passwd文件中没有匹配项
我正在尝试使用Visual Studio代码扩展远程容器从docker运行python代码。以下是Dockerfile:Python VS代码远程容器:外壳服务器终止(代码:126,信号:null)找不到用户xxx:passwd文件中没有匹配项,python,docker,visual-studio-code,Python,Docker,Visual Studio Code,我正在尝试使用Visual Studio代码扩展远程容器从docker运行python代码。以下是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 PYTHONUNBUFFERE
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"]
下面是.devcontainer.json:
{
"name": "Existing Dockerfile",
"context": "..",
"dockerFile": "Dockerfile",
"settings": {
"terminal.integrated.shell.linux": null
},
"extensions": [],
"remoteUser": "someuser"
}
当我运行它时,它会抛出一个错误:
Shell server terminated (code: 126, signal: null)
unable to find user someuser: no matching entries in passwd file
在容器中搜索passwd
文件时:
cat /etc/passwd
没有用户
someuser
我也有同样的问题。对我来说,一开始我忘记了创建vscode用户,所以我修改了映像以创建vscode用户,但是vscode没有更新以使用新映像
我必须手动删除vscode试图使用的(旧)容器。如果你去
远程容器:显示日志
您可以看到VSCode试图使用的容器的ID
然后,您可以使用以下方法杀死并移除容器:
docker kill $YOUR_ID_HERE
docker rm $YOUR_ID_HERE
然后告诉vscode再次尝试在远程容器中打开项目。它将被迫使用更新的图像创建新容器。如何创建用户?