0

我开始深入研究具有自定义功能的 VSCode 远程容器。我使用 dotfiles repo 让我有宾至如归的感觉,但我的 dotfiles(特别.zshrc是)是包(如:bat、exa、jq 等)。我不想将它直接推入,devcontainer因为我的其他同事不需要它们。

我尝试在我的dotfiles/install脚本中使用apt-get install -y jq但我收到并错误:

E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

我想知道在不与我的同事共享这些定制的情况下定制 devcontainer 的解决方案是什么?

提前致谢

4

1 回答 1

0

听起来您可能在容器中使用了非 root 用户。如果是这种情况,您需要做两件事:

  1. 安装 sudo 包并授予您的用户 sudo 权限。VSCode Dev Container 文档解释了如何做到这一点。您需要将其添加到您的 Dockerfile 中:
ARG USERNAME=user-name-goes-here
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

# ********************************************************
# * Anything else you want to do like clean up goes here *
# ********************************************************

# [Optional] Set the default user. Omit if you want to keep the default as root.
USER $USERNAME
  1. 更新您的安装脚本以使用 sudo:
sudo apt-get install -y jq
于 2022-02-07T13:03:04.540 回答