Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devcontainers lack bash-completion #1164

Open
thetredev opened this issue Oct 29, 2024 · 1 comment
Open

devcontainers lack bash-completion #1164

thetredev opened this issue Oct 29, 2024 · 1 comment

Comments

@thetredev
Copy link

thetredev commented Oct 29, 2024

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.

@thetredev thetredev changed the title docker-in-docker: feature lacks bash-completion devcontainers lack bash-completion Oct 29, 2024
@thetredev
Copy link
Author

thetredev commented Oct 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant