VS 代码远程容器:Shell 服务器终止(代码:126,信号:空)无法找到用户 xxx:passwd 文件中没有匹配的条目

alt*_*ego 5 python docker visual-studio-code

我正在尝试使用 Visual Studio Code 扩展远程容器从 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 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"] 
Run Code Online (Sandbox Code Playgroud)

这是 .devcontainer.json:

{
    "name": "Existing Dockerfile",

    "context": "..",

    "dockerFile": "Dockerfile",

    "settings": { 
        "terminal.integrated.shell.linux": null
    },
    "extensions": [],
     "remoteUser": "someuser"
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,它抛出一个错误:

Shell server terminated (code: 126, signal: null)
unable to find user someuser: no matching entries in passwd file
Run Code Online (Sandbox Code Playgroud)

当我passwd在容器内搜索文件时:

cat /etc/passwd
Run Code Online (Sandbox Code Playgroud)

没有用户 someuser

Inc*_*tic 12

我遇到过同样的问题。对我来说,我一开始忘记创建我的 vscode 用户,所以我修改了我的映像来创建 vscode 用户,但 vscode 没有更新以使用新映像。

我必须手动删除 vscode 尝试使用的(旧)容器。如果你去

远程容器:显示日志

您可以看到 VSCode 尝试使用的容器的 ID。

然后,您可以使用以下命令杀死并删除容器:

docker kill $YOUR_ID_HERE
docker rm $YOUR_ID_HERE
Run Code Online (Sandbox Code Playgroud)

然后告诉 vscode 再次尝试在远程容器中打开项目。它将被迫使用更新的映像创建一个新容器。

  • 如何创建用户? (4认同)

Cam*_*ron 5

我遇到了这个问题,但实际上这个问题对我来说有两个部分。

前半部分是我基于 vscode 示例远程容器的一些配置,包括 devcontainer.json 中的以下行:

// Comment out this line to run as root instead.
"remoteUser": "vscode"
Run Code Online (Sandbox Code Playgroud)

但我也尝试使用我自己的 docker 映像之一,因此该用户vscode不存在于我的 docker 映像中。如果您只是注释掉配置行或者只是将其切换到您知道存在的用户(即可能root),那么假设您从干净的或新的容器开始,这将解决问题。

正如前面所说,后半部分Increasingly Idiotic是,您可能需要关闭/删除旧容器,因为它可能会保存您以前的用户名,即使您已经更新了 devcontainer.json 文件。因此,即使更新了值,重建也会失败remoteUser