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 installing feature node #440

Closed
samstride opened this issue Feb 6, 2023 · 14 comments
Closed

Error installing feature node #440

samstride opened this issue Feb 6, 2023 · 14 comments

Comments

@samstride
Copy link

Hi,

With a json file like this:

"features": {
		"ghcr.io/devcontainers/features/common-utils:2": {},
		"ghcr.io/devcontainers/features/node:1": {
			"version": "lts"
		},
		"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
			"version": "latest",
			"moby": false,
			"dockerDashComposeVersion": "v2"
		}
	},

I get the following error during start up:

#0 9.905 Now using node v18.14.0 (npm v9.3.1)
#0 9.979 Creating default alias: default -> lts/* (-> v18.14.0 *)
#0 10.03 => Node.js version lts/* has been successfully installed
#0 10.03 => Close and reopen your terminal to start using nvm or run the following to use it now:
#0 10.03 
#0 10.03 export NVM_DIR="/usr/local/share/nvm"
#0 10.03 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
#0 10.03 sh: 6: source: not found
#0 10.03 ERROR: Feature "Node.js (via nvm) and yarn" (ghcr.io/devcontainers/features/node) failed to install! Look at the documentation at https://github.com/devcontainers/features/tree/main/src/node for help troubleshooting this error.

Thanks.

@samruddhikhandale
Copy link
Member

Hi 👋

I tried to reproduce with this dev container 👇

{
    "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
    "features": {
		"ghcr.io/devcontainers/features/common-utils:2": {},
		"ghcr.io/devcontainers/features/node:1": {
			"version": "lts"
		},
		"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
			"version": "latest",
			"moby": false,
			"dockerDashComposeVersion": "v2"
		}
	},
}

The node Feature installed without any errors for me.

@samstride Can you paste your entire dev config? That might help investigate.
Also, what's the Dev Container Extension CLI version?

@samstride
Copy link
Author

samstride commented Feb 7, 2023

@samruddhikhandale

Image looks like this:

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

FROM golang:1.20.0-bullseye

ARG USERNAME
ARG USER_UID
ARG USER_GID

# Create the user
RUN groupadd --gid ${USER_GID} ${USERNAME} \
    && useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME}

# Install some common packages
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install \
    git-all \
    vim \
    clang-format \
    ca-certificates \
    curl \
    gnupg \
    pass \
    lsb-release \
    --no-install-recommends

Config looks like this:

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/go
{
	"name": "dev",
	"build": {
		"dockerfile": "Dockerfile"
	},
	"runArgs": [
		"--cap-add=SYS_PTRACE",
		"--security-opt",
		"seccomp=unconfined"
	],
	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			// Set *default* container specific settings.json values on container create.
			"settings": {
				"terminal.integrated.defaultProfile.linux": "zsh",
			},
			// Add the IDs of extensions you want installed when the container is created.
			"extensions": [
				"golang.Go",
				"ms-azuretools.vscode-docker",
				"zxh404.vscode-proto3",
				"xaver.clang-format",
				"ms-kubernetes-tools.vscode-kubernetes-tools",
				"yzhang.markdown-all-in-one",
				"bradymholt.pgformatter",
				"emeraldwalk.runonsave",
				"redhat.vscode-xml",
				"redhat.vscode-yaml",
				"dbaeumer.vscode-eslint"
			]
		}
	},
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],
	// Use 'postCreateCommand' to run commands after the container is created.
	"postCreateCommand": "devcontainer/init.sh", //Custom install script.
	// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
	"remoteUser": "vscode",
	"features": {
		"ghcr.io/devcontainers/features/common-utils:2": {},
		"ghcr.io/devcontainers/features/node:1": {
			"version": "lts"
		},
		"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
			"version": "latest",
			"moby": false,
			"dockerDashComposeVersion": "v2"
		}
	},
	"containerEnv": {
		"TZ": "Pacific/Auckland"
	}
}

Extension version = v0.275.1

Thanks.

@samruddhikhandale
Copy link
Member

samruddhikhandale commented Feb 7, 2023

The issue is with your Dockerfile not correctly adding and setting the vscode user. As user is not set properly, the nvm install fails.

@samstride Can you update your devcontainer.json as follows? This solved the issue for me
Using the common-utils Feature to add the vscode user

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/go
{
	"name": "dev",
	"image": "golang:1.20.0-bullseye",
	"runArgs": [
		"--cap-add=SYS_PTRACE",
		"--security-opt",
		"seccomp=unconfined"
	],
	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			// Set *default* container specific settings.json values on container create.
			"settings": {
				"terminal.integrated.defaultProfile.linux": "zsh"
			},
			// Add the IDs of extensions you want installed when the container is created.
			"extensions": [
				"golang.Go",
				"ms-azuretools.vscode-docker",
				"zxh404.vscode-proto3",
				"xaver.clang-format",
				"ms-kubernetes-tools.vscode-kubernetes-tools",
				"yzhang.markdown-all-in-one",
				"bradymholt.pgformatter",
				"emeraldwalk.runonsave",
				"redhat.vscode-xml",
				"redhat.vscode-yaml",
				"dbaeumer.vscode-eslint"
			]
		}
	},
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],
	// Use 'postCreateCommand' to run commands after the container is created.
	"postCreateCommand": "devcontainer/init.sh", //Custom install script.
	// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
	"remoteUser": "vscode",
	"features": {
		"ghcr.io/devcontainers/features/common-utils:2": {
            "username": "vscode"
        },
		"ghcr.io/devcontainers/features/node:1": {
			"version": "lts"
		},
		"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
			"version": "latest",
			"moby": false,
			"dockerDashComposeVersion": "v2"
		}
	},
	"containerEnv": {
		"TZ": "Pacific/Auckland"
	}
}

ℹ️ Also, opened devcontainers/images#412, we would release go:1.20 tomorrow, then you could simply use that image and avoid using common-utils Feature and remove some other properties (like remoteUser, few extensions) as well.

tip: The docker-outside-of-docker, adds the run-args, feel free to skip them!

@samstride
Copy link
Author

samstride commented Feb 7, 2023

@samruddhikhandale , thanks.

The issue is with your Dockerfile not correctly adding and setting the vscode user. As user is not set properly, the nvm install fails.

Can you elaborate on that. I was using this guide here: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user

My bad, I forgot to paste the end of my Dockerfile, which is:

USER ${USERNAME}
# Install few other packages
.
.
>

I used the setting :

"ghcr.io/devcontainers/features/common-utils:2": {
  "username": "vscode"
}

and I still get the same error.

Btw, thanks for the tip 👍

tip: The docker-outside-of-docker, adds the run-args, feel free to skip them!

information_source Also, opened devcontainers/images#412, we would release go:1.20 tomorrow, then you could simply use that image and avoid using common-utils Feature and remove some other properties (like remoteUser, few extensions) as well.

Hmmm, this one is a tricky one. Historically, the go feature can be 1+ weeks late. Hence, we decided to use the official image which is usually out within a few hours of the go release.

@samruddhikhandale
Copy link
Member

samruddhikhandale commented Feb 7, 2023

mcr.microsoft.com/devcontainers/go:1.20 image is live.
@samstride Can you update the image property and remove the common-utils Feature? That should fix your issue.

Feel free to reopen if the issue resurfaces!

@samstride
Copy link
Author

@samruddhikhandale , Thanks.

Still curious to know what is the correct way to set the user:

The issue is with your Dockerfile not correctly adding and setting the vscode user. As user is not set properly, the nvm install fails.

I was using this guide here: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user

@samruddhikhandale
Copy link
Member

I am not sure what's the exact issue was in there (I'll take a peek), but it's nice to use the common-utils Feature for that purpose.

@samstride
Copy link
Author

samstride commented Feb 7, 2023

@samstride Can you update the image property and remove the common-utils Feature? That should fix your issue.

If we remove common-utils, it means that zsh and oh-my-zsh will not be setup, which we want in the dev container.

Also, the issue seems to pop up only if node feature is used. (nvm seems to be causing an issue). Without that feature, everything else seems to work.

@kosperera
Copy link

kosperera commented Feb 11, 2023

@samruddhikhandale @samstride have you found a fix for this issue?

I am getting the same error after migrating from @microsoft/vscode-dev-containers.
Here's my complete devcontainer.json looks like. I tried setting the user vscode in both places mentioned above but no luck.

I use VS Code v1.75.1 with Docker Desktop v4.16.2 (95914) on Apple M1 Ventura v13.2, if that helps.

@samstride
Copy link
Author

samstride commented Feb 12, 2023

@kosalanuwan , I never got it to work. Are you getting the exact same error? Does your devcontainer work if you remove node?

Since I use my own images (mostly because I want to maintain my own velocity), I installed node in the base image.

You could do something like this in your json to see if it will work:

// "image": "mcr.microsoft.com/devcontainers/base:dev-bullseye",
"build": {
		"dockerfile": "Dockerfile"
	},

Then create a Dockerfile in .devcontainer as follows:

FROM mcr.microsoft.com/devcontainers/base:dev-bullseye

# Install NodeJS LTS
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - &&\
    apt-get install -y nodejs

... and don't forget to remove the feature node in your json if you build your own Dockerfile like above.

@samruddhikhandale
Copy link
Member

@kosalanuwan Can you remove the common-utils Feature and retry? The base image is adding the vscode user with the common-utils Feature. I suspect that's the issue.

@kosperera
Copy link

@kosalanuwan Can you remove the common-utils Feature and retry? The base image is adding the vscode user with the common-utils Feature. I suspect that's the issue.

@samruddhikhandale this worked for me! Appreciate the support 🥳

@brcarp
Copy link

brcarp commented Jun 4, 2023

Still curious to know what is the correct way to set the user:

The issue is with your Dockerfile not correctly adding and setting the vscode user. As user is not set properly, the nvm install fails.

I was using this guide here: https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_creating-a-nonroot-user

I ran into this same issue and finally figured out what was happening. The guide for creating a nonroot user (linked to above) calls useradd but without a -s option to set the login shell. I believe it's a bug, but devcontainers/features/node is essentially expecting this to be bash because it has an explicit source in this line of install.sh. However if you don't add -s /bin/bash to the useradd then you get /bin/sh by default as the login shell for the user, which yields the sh: 6: source: not found error.

The simplest resolution is to add -s /bin/bash to your useradd command. Zooming out however I think this is a bug in devcontainers/features and I'm going to create an issue for it.

@kosperera
Copy link

@kosalanuwan , I never got it to work. Are you getting the exact same error? Does your devcontainer work if you remove node?

@samstride I'd avoid managing Dockerfiles, so I use the dotnet/sdk:8.0-bookworm-slim image.

@samruddhikhandale It works fine with the common-utils and node features together. This is on an Apple M1 (2020) running Sonoma 14.1.1.

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

No branches or pull requests

4 participants