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

Error when creating new dev container using basecloj template #29

Open
alza-bitz opened this issue Jan 28, 2025 · 5 comments
Open

Error when creating new dev container using basecloj template #29

alza-bitz opened this issue Jan 28, 2025 · 5 comments

Comments

@alza-bitz
Copy link

Hi there, when I attempt to create a new dev container using the basecloj template in VSCode, it makes some progress but ultimately fails.

I didn't look too far into the cause but it seems like some $USERNAME script var is empty, so the groupadd command fails due to a missing argument.

I did see that ARG USERNAME=vscode is present in the Dockerfile so I don't understand how this is happening, but there you go:

[10460 ms] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.72.0-1738105208356/Dockerfile-with-features -t vsc-basecloj-93cbbf93d1175c8cf32f6dd538d1ea9f635fddfbd28782b12b9240f6d38e4c28 --target dev_containers_target_stage --build-arg BASE_IMAGE=temurin-21-tools-deps-jammy --build-arg USERNAME= --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.72.0-1738105208356 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /workspaces/basecloj/.devcontainer
[+] Building 1.3s (9/17)                                                                                           docker:default
 => [internal] load build definition from Dockerfile-with-features                                                           0.0s
 => => transferring dockerfile: 2.84kB                                                                                       0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 2B                                                                                              0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4                                                                 0.4s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef  0.0s
 => [context dev_containers_feature_content_source] load .dockerignore                                                       0.0s
 => => transferring dev_containers_feature_content_source: 2B                                                                0.0s
 => [internal] load metadata for docker.io/library/clojure:temurin-21-tools-deps-jammy                                       0.4s
 => CACHED [dev_container_auto_added_stage_label 1/4] FROM docker.io/library/clojure:temurin-21-tools-deps-jammy@sha256:ebe  0.0s
 => [context dev_containers_feature_content_source] load from client                                                         0.0s
 => => transferring dev_containers_feature_content_source: 22.88kB                                                           0.0s
 => ERROR [dev_container_auto_added_stage_label 2/4] RUN groupadd --gid 1000      && useradd --uid 1000 --gid 1000 -m        0.4s
------
 > [dev_container_auto_added_stage_label 2/4] RUN groupadd --gid 1000      && useradd --uid 1000 --gid 1000 -m      && apt-get update     && apt-get install -y sudo     && echo  ALL=(root) NOPASSWD:ALL > /etc/sudoers.d/     && chmod 0440 /etc/sudoers.d/:
0.341 Usage: groupadd [options] GROUP
0.341 
0.341 Options:
0.341   -f, --force                   exit successfully if the group already exists,
0.341                                 and cancel -g if the GID is already used
0.341   -g, --gid GID                 use GID for the new group
0.341   -h, --help                    display this help message and exit
0.341   -K, --key KEY=VALUE           override /etc/login.defs defaults
0.341   -o, --non-unique              allow to create groups with duplicate
0.341                                 (non-unique) GID
0.341   -p, --password PASSWORD       use this encrypted password for the new group
0.341   -r, --system                  create a system account
0.341   -R, --root CHROOT_DIR         directory to chroot into
0.341   -P, --prefix PREFIX_DIR       directory prefix
0.341       --extrausers              Use the extra users database
0.341 
------
Dockerfile-with-features:11
--------------------
  10 |     # Create the user
  11 | >>> RUN groupadd --gid $USER_GID $USERNAME \
  12 | >>>     && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
  13 | >>>     #
  14 | >>>     # [Optional] Add sudo support. Omit if you don't need to install software after connecting.
  15 | >>>     && apt-get update \
  16 | >>>     && apt-get install -y sudo \
  17 | >>>     && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
  18 | >>>     && chmod 0440 /etc/sudoers.d/$USERNAME
  19 |         
--------------------
ERROR: failed to solve: process "/bin/sh -c groupadd --gid $USER_GID $USERNAME     && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME     && apt-get update     && apt-get install -y sudo     && echo $USERNAME ALL=\\(root\\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME     && chmod 0440 /etc/sudoers.d/$USERNAME" did not complete successfully: exit code: 2
[12171 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.72.0-1738105208356/Dockerfile-with-features -t vsc-basecloj-93cbbf93d1175c8cf32f6dd538d1ea9f635fddfbd28782b12b9240f6d38e4c28 --target dev_containers_target_stage --build-arg BASE_IMAGE=temurin-21-tools-deps-jammy --build-arg USERNAME= --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.72.0-1738105208356 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /workspaces/basecloj/.devcontainer
@alza-bitz
Copy link
Author

Looking at the log again I can see

docker buildx build ... --build-arg USERNAME= ...

So the value of USERNAME is not being passed for some reason..

@behrica
Copy link
Member

behrica commented Jan 29, 2025

yes, I have seen that as well (sometimes)
I think it depens on the "docker host".

Most OS have environemnt variable 'USER' set an then it does work.

We had as well an other issue about the same thing:
#27

@behrica
Copy link
Member

behrica commented Jan 29, 2025

so this should fix it:

"args": {
"USERNAME": "${localEnv:USER:VSCODE}"
}

Can you try , please ?

@behrica
Copy link
Member

behrica commented Jan 29, 2025

I just noticed that we never "published" the fix done in #27.
I just did that know, so we have a template with version 1.0.2 now, which hopefully fixes the issue as well for you.

Could you maybe try the latest version of the template (1.0.2) ?

@alza-bitz
Copy link
Author

Hi there, thanks for picking this up. I tried again earlier today from the VSCode ui directly, and it now works. So I guess VSCode must be picking up newer template versions automatically. I didn't try with the other devcontainer cmdline method.

One other point of note, the other template scicloj didn't have this issue.. it's devcontainer.json is different, it doesn't even have the build args section. Also, I am clearly missing a trick in how things get bootstrapped because in both cases the Dockerfile has the USERNAME hard-coded to vscode 🤔

Anyway this can be closed now, thanks!

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

2 participants