3

I start diving deep in VSCode Remote-container with customization. I use a dotfiles repo to feel at home but my dotfiles (specially .zshrc) is packages (like: bat, exa, jq and more). I don't want to push it directly in the devcontainer because my other co-worker don't need them.

I try to do it in my dotfiles/install script using apt-get install -y jq but I receive and error:

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?

I wonder what is the solution to customize the devcontainer without sharing these customization with my co-worker?

Thanks in advance

mazerte
  • 31
  • 2

1 Answers1

3

It sounds like you may be using a non-root user in your container. If that is the case, you need to do two things:

  1. Install the sudo package and give your user sudo privileges. The VSCode Dev Container docs explain how to do that. You'll need to add this to your 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. Update your install script to use sudo:
sudo apt-get install -y jq
Eric G
  • 76
  • 1