install Dev Containers (ms-vscode-remote.remote-containers) extension
Config docker context
Docker context defines the endpoint (i.e., the target Docker Engine) that the Docker CLI talks to. This allows you to easily switch between local Docker engines, remote Docker hosts
{"name":"Remote DevContainer","workspaceFolder":"/workspaces/vscode_remote_devcontainer","build":{"dockerfile":"Dockerfile"},"remoteUser":"user","runArgs":["--network=host"],"postCreateCommand":"echo 'DevContainer is ready!'"}
Dockerfile
Base on ubuntu 22.04 add none root user and install and config sudo
FROMubuntu:22.04ARGDEBIAN_FRONTEND=noninteractive
ARGUSERNAME=user
ARGUSER_UID=1000ARGUSER_GID=$USER_UID# Check if "ubuntu" user exists, delete it if it does, then create the desired userRUNifgetentpasswdubuntu>/dev/null2>&1;then\userdel-rubuntu&&\echo"Deleted existing ubuntu user";\fi&&\groupadd--gid$USER_GID$USERNAME&&\useradd-s/bin/bash--uid$USER_UID--gid$USER_GID-m$USERNAME&&\echo"Created new user $USERNAME"# Add sudo support for the non-root userRUNapt-getupdate&&apt-getinstall-ysudo\&&echo$USERNAMEALL=\(root\)NOPASSWD:ALL>/etc/sudoers.d/$USERNAME\&&chmod0440/etc/sudoers.d/$USERNAME\&&rm-rf/var/lib/apt/lists/*
ARGDEBIAN_FRONTEND=