microsoft / microsoft/vscode-remote-release

localEnv in devcontainer does not have either $HOST or $HOSTNAME

Open
#11,084 6 comments 0 reactions 1 assignee View on GitHub

@chrmarti is already working on this.

Since Jul 11, 2025.

containers info-needed
Dominant language
Dockerfile
Stars
4.2k
Forks
469
Avg merge
1d 1h
Merged PRs (30d)
1

Description

My system:

  • Distro: Arch Linux
  • Shell: zsh
  • Integrated terminal: zsh
  • VSCode:
Version: 1.102.0
Commit: cb0c47c0cfaad0757385834bd89d410c78a856c0
Date: 2025-07-09T22:10:34.600Z
Electron: 35.6.0
ElectronBuildId: 11847422
Chromium: 134.0.6998.205
Node.js: 22.15.1
V8: 13.4.114.21-electron.0
OS: Linux x64 6.15.6-arch1-1

I am trying to login as the 'ubuntu' user in an ubuntu container, and wanted to get rid of the sudo: unable to resolve host warning whenever I try to use sudo. A fix was to pass in my hostname in runArgs, but somehow localEnv has neither $HOST nor $HOSTNAME.

My integrated terminal is zsh, and running echo $HOST in it gives me my hostname correctly.
However when i try to pass that into the container using "--add-host=${localEnv:HOST}:127.0.0.1", I get the error invalid argument ":127.0.0.1" for "--add-host" flag: bad format for add-host: ":127.0.0.1" I tried using localEnv:HOSTNAME as well but I get the same error. Just using my hostname directly, --add-host=akshatd-tp:127.0.0.1 works as expected.

Any help will be appreciated!

My Dockerfile

FROM osrf/ros:kilted-desktop

RUN apt update && apt upgrade -y

# Install dbus-x11 for GUI applications and prevent
# "Unable to acquire session bus: Failed to execute child process “dbus-launch” (No such file or directory)"
RUN apt install -y dbus-x11

# Add dbus launch vars to .bashrc to prevent dbus errors when launching GUI applications
# https://stackoverflow.com/questions/20285697/error-in-spawning-a-dbus-launch-what-is-that
# https://github.com/moby/moby/issues/34175#issuecomment-727772434
RUN echo "export \$(dbus-launch)" >> /root/.bashrc
RUN echo "export \$(dbus-launch)" >> /home/ubuntu/.bashrc

# https://gazebosim.org/docs/latest/ros_installation/
RUN apt install -y \
  gnome-text-editor \
  ros-${ROS_DISTRO}-ros-gz

# Change the default ubuntu user's password to 'ubuntu'
# https://stackoverflow.com/questions/66190675/docker-set-user-password-non-interactively
RUN echo "ubuntu:ubuntu" | chpasswd

# Add ROS2 aliases and environment setup
RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> /root/.bashrc
RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> /home/ubuntu/.bashrc

My .devcontainer file

{
	"dockerFile": "Dockerfile",
	"remoteUser": "ubuntu",
	"containerEnv": {
		// Environment variables to access the host's display for GUI applications
		"DISPLAY": "${localEnv:DISPLAY}",
		// if this doesnt work, XAUTHORITY needs to be modified. use `xhost +local:docker` to allow GUI access instead
		// see https://github.com/hemashushu/docker-archlinux-gui?tab=readme-ov-file#map-x11
		"XAUTHORITY": "${localEnv:XAUTHORITY}",
		"XDG_RUNTIME_DIR": "${localEnv:XDG_RUNTIME_DIR}",
		"WAYLAND_DISPLAY": "${localEnv:WAYLAND_DISPLAY}",
		"GTK_A11Y": "none" // Disable accessibility features to prevent warnings when running GTK GUI applications
	},
	"runArgs": [
		"--privileged", // dirty hack for GPU access
		"--network=host",
		// https://docs.docker.com/config/containers/resource_constraints/
		"--memory=6g",
		"--cpus=6",
		// https://answers.ros.org/question/336963/rosout-high-memory-usage/
		// Equal sign needed: https://stackoverflow.com/questions/73106697/how-to-setup-ulimit-nofile-in-devcontainer-vscode
		"--ulimit=nofile=1024:4096",
		// Add hostname to /etc/hosts to prevent "sudo: unable to resolve host" warnings
		// "--add-host=akshatd-tp:127.0.0.1", // TODO: fix this by using localEnv
		"--add-host=${localEnv:HOST}:127.0.0.1"
	],
	"mounts": [
		// Mounts the X11 socket and XAUTHORITY file for GUI applications
		"source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind",
		"source=${localEnv:XDG_RUNTIME_DIR},target=${localEnv:XDG_RUNTIME_DIR},type=bind"
	],
	"customizations": {
		"vscode": {
			"settings": {
				"terminal.integrated.defaultProfile.linux": "bash",
				"terminal.integrated.profiles.linux": {
					"bash": {
						"path": "/bin/bash"
					}
				}
			}
			// "extensions": [
			// 	"ms-python.python",
			// 	"ms-python.autopep8",
			// 	"ms-vscode.cpptools",
			// 	"github.copilot",
			// 	"github.copilot-chat"
			// ]
		}
	}
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.