devcontainers lack bash-completion
I was messing around with devcontainers lately and I realized that there was no bash completion for the docker command inside a devcontainer with the docker-in-docker feature enabled like this:
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"moby": true,
"azureDnsAutoDetection": false,
"defaultDockerAddressPool": "172.19.0.0/16,size=24",
"installDockerBuildx": true
}
}
I boiled it down to .bashrc not being evaluated, because the shell that is launched inside the devcontainer is not a login shell (e.g., /bin/bash called without -l). This is also the case for the mcr.microsoft.com/devcontainers/base image for example, which has the following values for ENTRYPOINT and CMD:
"Cmd": [
"bash"
],
"Entrypoint": null,
I tried pointing the devcontainer to a Dockerfile with modified ENTRYPOINT and CMD to no avail:
{
"name": "Test container",
"build": {
"dockerfile": "Dockerfile"
}
}
FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm
ENTRYPOINT [ "/bin/bash", "-l" ]
CMD []
Is there anything we can do from the user side to workaround the issue? It would be best if VS Code would run a login shell inside the devcontainer but I guess that is a VS Code issue rather than a devcontainer one, so I guess a workaround would be fine, considering that you might not even want a login shell in certain scenarios.
The easiest way to reproduce it is with the following Dockerfile:
FROM mcr.microsoft.com/devcontainers/base:bookworm
RUN distro=$(. /etc/os-release && echo "$ID") \
&& distro_version=$(. /etc/os-release && echo "$VERSION_CODENAME") \
&& apt-get -y update \
&& apt-get -y install \
ca-certificates \
curl \
gnupg2 \
bash-completion \
&& install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/${distro}/gpg -o /etc/apt/keyrings/docker.asc \
&& chmod a+r /etc/apt/keyrings/docker.asc \
&& mkdir -p /etc/apt/sources.list.d \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/${distro} ${distro_version} stable" > /etc/apt/sources.list.d/docker.list \
&& apt-get -y update \
&& apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin
# these are not needed, but it's better to explicitly unset them to have a defined baseline for testing
ENTRYPOINT []
CMD []
and running one of these commands after building the image:
# bash completion via TAB key for the docker command is not available:
docker run --rm -it <image previously built> bash
# bash completion via TAB key for the docker command is available:
docker run --rm -it <image previously built> bash -l