devcontainers / features

A collection of Dev Container Features managed by Dev Container spec maintainers. See https://github.com/devcontainers/feature-starter to publish your own
https://containers.dev/features
MIT License
897 stars 363 forks source link

groupadd: GID '1000' already exists #531

Open raymond-chetty opened 1 year ago

raymond-chetty commented 1 year ago

It looks like it is an error to set the GID to 1000 when installing the common-utils feature on a debian base in codespaces. It's possible this is a codespaces issue... or maybe the base image includes a common-utils feature which creates a 1000 group. Once created the id isn't overridden in the codespaces devcontainer.json file that includes the feature.

https://github.com/devcontainers/images/blob/main/src/base-debian/.devcontainer/devcontainer.json#L7 https://github.com/devcontainers/features/blob/main/src/common-utils/main.sh#L362

I created the devcontainer.json below using the vscode wizard in github codespaces.... F1 -> Add Dev Container Configuration Files... -> Create new configuration -> Debian -> bullseye -> Common utilities -> meson -> bazel -> android sdk -> android sdk platform tools -> ok -> configure options -> emulator -> ok -> 33 -> 33.0.2 -> v1.15.0 -> nonFreePackages -> ok -> devcontainer -> 1000 -> 1000

2023-04-26 20:08:02.133Z: #17 0.515 ===========================================================================
#17 0.515 Feature       : Common Utilities
#17 0.515 Description   : Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.
#17 0.515 Id            : ghcr.io/devcontainers/features/common-utils
#17 0.515 Version       : 2.0.8
#17 0.515 Documentation : https://github.com/devcontainers/features/tree/main/src/common-utils
#17 0.515 Options       :
#17 0.515     INSTALLZSH="true"
#17 0.515     CONFIGUREZSHASDEFAULTSHELL="false"
#17 0.515     INSTALLOHMYZSH="true"
#17 0.515     UPGRADEPACKAGES="true"
#17 0.515     USERNAME="devcontainer"
#17 0.515     USERUID="1000"
#17 0.515     USERGID="1000"
#17 0.515     NONFREEPACKAGES="true"
2023-04-26 20:08:02.241Z: #17 0.522 ===========================================================================
#17 0.587 Marker file found:
#17 0.590     PACKAGES_ALREADY_INSTALLED=true
#17 0.590     LOCALE_ALREADY_SET=true
#17 0.590     EXISTING_NON_ROOT_USER=vscode
#17 0.590     RC_SNIPPET_ALREADY_ADDED=true
#17 0.590     ZSH_ALREADY_INSTALLED=true
#17 0.623 
2023-04-26 20:08:02.343Z: #17 0.629 ERROR: Feature "Common Utilities" (ghcr.io/devcontainers/features/common-utils) failed to install! Look at the documentation at https://github.com/devcontainers/features/tree/main/src/common-utils for help troubleshooting this error.
#17 ERROR: executor failed running [/bin/sh -c cp -ar /tmp/build-features-src/common-utils_1 /tmp/dev-container-features  && chmod -R 0755 /tmp/dev-container-features/common-utils_1  && cd /tmp/dev-container-features/common-utils_1  && chmod +x ./devcontainer-features-install.sh  && ./devcontainer-features-install.sh  && rm -rf /tmp/dev-container-features/common-utils_1]: exit code: 4
------
 > [dev_containers_target_stage 5/9] RUN --mount=type=bind,from=dev_containers_feature_content_source,source=common-utils_1,target=/tmp/build-features-src/common-utils_1     cp -ar /tmp/build-features-src/common-utils_1 /tmp/dev-container-features  && chmod -R 0755 /tmp/dev-container-features/common-utils_1  && cd /tmp/dev-container-features/common-utils_1  && chmod +x ./devcontainer-features-install.sh  && ./devcontainer-features-install.sh  && rm -rf /tmp/dev-container-features/common-utils_1:
#17 0.515     NONFREEPACKAGES="true"
#17 0.522 ===========================================================================
#17 0.587 Marker file found:
#17 0.590     PACKAGES_ALREADY_INSTALLED=true
#17 0.590     LOCALE_ALREADY_SET=true
#17 0.590     EXISTING_NON_ROOT_USER=vscode
#17 0.590     RC_SNIPPET_ALREADY_ADDED=true
#17 0.590     ZSH_ALREADY_INSTALLED=true
#17 0.623 groupadd: GID '1000' already exists
#17 0.629 ERROR: Feature "Common Utilities" (ghcr.io/devcontainers/features/common-utils) failed to install! Look at the documentation at https://github.com/devcontainers/features/tree/main/src/common-utils for help troubleshooting this error.
------
ERROR: failed to solve: executor failed running [/bin/sh -c cp -ar /tmp/build-features-src/common-utils_1 /tmp/dev-container-features  && chmod -R 0755 /tmp/dev-container-features/common-utils_1  && cd /tmp/dev-container-features/common-utils_1  && chmod +x ./devcontainer-features-install.sh  && ./devcontainer-features-install.sh  && rm -rf /tmp/dev-container-features/common-utils_1]: exit code: 4
2023-04-26 20:08:02.346Z: Stop: Run: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.37.0-1682539652479 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:bullseye --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-codespaces-blank-6ddb1da97a62cb20a5a675bfb2d37ebadcb57a94646c29490eab9ebed016e64b-features -f /tmp/devcontainercli-root/container-features/0.37.0-1682539652479/Dockerfile.extended /var/lib/docker/codespacemount/.persistedshare/empty-folder
2023-04-26 20:08:02.359Z: {"outcome":"error","message":"Command failed: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.37.0-1682539652479 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:bullseye --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-codespaces-blank-6ddb1da97a62cb20a5a675bfb2d37ebadcb57a94646c29490eab9ebed016e64b-features -f /tmp/devcontainercli-root/container-features/0.37.0-1682539652479/Dockerfile.extended /var/lib/docker/codespacemount/.persistedshare/empty-folder","description":"An error occurred setting up the container."}
2023-04-26 20:08:02.385Z: Error: Command failed: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.37.0-1682539652479 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:bullseye --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-codespaces-blank-6ddb1da97a62cb20a5a675bfb2d37ebadcb57a94646c29490eab9ebed016e64b-features -f /tmp/devcontainercli-root/container-features/0.37.0-1682539652479/Dockerfile.extended /var/lib/docker/codespacemount/.persistedshare/empty-folder
2023-04-26 20:08:02.388Z:     at wse (/usr/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:1916:3264)
2023-04-26 20:08:02.390Z:     at K7 (/usr/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:1916:3200)
2023-04-26 20:08:02.393Z:     at processTicksAndRejections (internal/process/task_queues.js:95:5)
2023-04-26 20:08:02.394Z:     at async Hse (/usr/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:1931:2626)
2023-04-26 20:08:02.395Z:     at async Ch (/usr/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:1931:3741)
2023-04-26 20:08:02.397Z:     at async cae (/usr/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2059:17376)
2023-04-26 20:08:02.398Z:     at async uae (/usr/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:2059:17117)
2023-04-26 20:08:02.399Z: devcontainer process exited with exit code 1

====================================== ERROR ====================================
2023-04-26 20:08:02.401Z: Failed to create container.
=================================================================================
2023-04-26 20:08:02.402Z: Error: Command failed: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.37.0-1682539652479 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/base:bullseye --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-codespaces-blank-6ddb1da97a62cb20a5a675bfb2d37ebadcb57a94646c29490eab9ebed016e64b-features -f /tmp/devcontainercli-root/container-features/0.37.0-1682539652479/Dockerfile.extended /var/lib/docker/codespacemount/.persistedshare/empty-folder
2023-04-26 20:08:02.405Z: Error Code: 1302

====================================== ERROR ====================================
2023-04-26 20:08:02.419Z: Container creation failed.
=================================================================================
2023-04-26 20:08:02.431Z: 
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
    "name": "Debian",
    // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
    "image": "mcr.microsoft.com/devcontainers/base:bullseye",
    "features": {
        "ghcr.io/devcontainers/features/common-utils:2": {
            "installZsh": true,
            "installOhMyZsh": true,
            "upgradePackages": true,
            "nonFreePackages": true,
            "username": "devcontainer",
            "userUid": "1000",
            "userGid": "1000"
        },
        "ghcr.io/devcontainers-contrib/features/meson-asdf:2": {
            "version": "latest"
        },
        "ghcr.io/balazs23/devcontainers-features/bazel:1": {
            "bazelisk": "v1.15.0"
        },
        "ghcr.io/akhildevelops/devcontainer-features/android-cli:0": {},
        "ghcr.io/jarrodcolburn/features/android-sdk:0": {
            "emulator": true,
            "platforms": "33",
            "build-tools": "33.0.2"
        }
    }

    // Features to add to the dev container. More info: https://containers.dev/features.
    // "features": {},

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [],

    // Configure tool-specific properties.
    // "customizations": {},

    // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
    // "remoteUser": "root"
}

Thanks!

samruddhikhandale commented 1 year ago

Hi 👋

The base:debian image already adds the common-utils Feature with GID 1000 to the image (See here). Hence, GID 1000 exists at image level

F1 -> Add Dev Container Configuration Files... -> Create new configuration -> Debian -> bullseye -> Common utilities -> meson -> bazel -> android sdk -> android sdk platform tools -> ok -> configure options -> emulator -> ok -> 33 -> 33.0.2 -> v1.15.0 -> nonFreePackages -> ok -> devcontainer -> 1000 -> 1000

As you are trying to add the common-utils Feature again on top of the image, it errors out as the GID is already allocated by the image to the vscode user.

@raymond-chetty Can you use a different GID and see if it helps?

samruddhikhandale commented 1 year ago

image

@joshspicer If I enter some value and click on ☑️ then nothing happens, is this a bug?

raymond-chetty commented 1 year ago

Is there a way to override the feature configuration used in the base image?

Maybe there is a way to use Metadata, options, or environment variables? https://containers.dev/implementors/json_reference/ https://containers.dev/implementors/features/#user-env-var https://containers.dev/implementors/spec/#image-metadata

I see remoteUser & containerUser have a last value wins merge logic, but nothing for groups except that some kind of sync gets done if a value is set to avoid bind mount problems. Maybe that is an implementation detail of github or limitation of devcontainers. https://containers.dev/implementors/spec/#container-creation

I probably shouldn't set the IDs, there isn't a reason for me currently, I mostly thought that the generated code wasn't working in a way that it seemed it should. And didn't recall it was mentioned in the base image documentation.

https://github.com/devcontainers/images/tree/main/src/base-debian Beyond git, this image / Dockerfile includes zsh, [Oh My Zsh!](https://ohmyz.sh/), a non-root vscode user with sudo access, and a set of common dependencies for development.

Possible things.... Improved documentation might be a good result from this issue if there isn't a code change that is needed to allow customization of GID to 1000. It doesn't say common-utils is added as a feature on the base image README.md... or that UID and GID 1000 are taken by the vscode user. Updating the install script not to assume that an addgroup call is needed and use usermod if the group already exists is another outcome, though it might be unintuitive.

From a user perspective, if I was just trying things out, I would expect that codespaces and vscode would allow me to create the devcontainer with a GID as 1000 if I followed the steps I described, but that might be a Microsoft & vscode issue.

You can close the issue as you see fit.

samruddhikhandale commented 1 year ago

Is there a way to override the feature configuration used in the base image?

Unfortunately, I don't think there is a way to currently override the GID used by the base image.

Maybe there is a way to use Metadata, options, or environment variables? https://containers.dev/implementors/json_reference/ https://containers.dev/implementors/features/#user-env-var https://containers.dev/implementors/spec/#image-metadata

I see remoteUser & containerUser have a last value wins merge logic, but nothing for groups except that some kind of sync gets done if a value is set to avoid bind mount problems. Maybe that is an implementation detail of github or limitation of devcontainers. https://containers.dev/implementors/spec/#container-creation

remoteUser & containerUser are properties of the devcontainer.json. However, gid is an option provided by the common-utils Feature, hence, I don't suspect that we would resolve gid with the merge logic which currently exists. However, if you think otherwise, then feel free to open a spec issue and provide your ideas/insights on how you would like to tackle this from the spec perspective.

Improved documentation might be a good result from this issue if there isn't a code change that is needed to allow customization of GID to 1000. It doesn't say common-utils is added as a feature on the base image README.md...

I agree that we should improve our documentation and add such details to avoid confusion. @raymond-chetty Would you be willing to contribute a PR with doc updates? We'd appreciate it.