Dev container features are modular, pre-built scripts and configurations that automatically install tools, libraries, or settings inside your dev container, without needing to write a full Dockerfile.
They are reusable building blocks to build and config containers.
Note
The feature run after The docker finish it build stage
{"name":"add none root user","id":"hello","version":"1.0.0","description":"add a non-root user with sudo","options":{"user":{"type":"string","proposals":["user"],"default":"user","description":"The name of the user to create."}}}
#!/bin/bashset-e
USERNAME=${USER}USER_UID=1000USER_GID=$USER_UID# Check if "ubuntu" user exists, delete it if it does, then create the desired userifgetentpasswdubuntu>/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 userapt-getupdate&&apt-getinstall-ysudo\&&echo$USERNAMEALL=\(root\)NOPASSWD:ALL>/etc/sudoers.d/$USERNAME\&&chmod0440/etc/sudoers.d/$USERNAME\&&rm-rf/var/lib/apt/lists/*
variable
To use variable declare in devcontainer-feature.json in the install.sh use the name uppercase ${USER}