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] npm unavailable after installing on python:3.11-slim-bookworm docker image #1790

Closed
SamStephens opened this issue Mar 26, 2024 · 4 comments
Assignees
Labels

Comments

@SamStephens
Copy link

Describe your bug

When I try and install using the setup script against the base Docker image python:3.11-slim-bookworm, npm is not available.

The failure looks similar to #1770, however I'm using the setup script as that issue says I should. I've tried using the pinning workaround detailed in that issue, and it doesn't help.

The issue appears to be with using the slimmed down base image, using python:3.11-bookworm as the image does work. However if the failure is because the slimmed down base image doesn't include required dependencies, I'd expect the setup script to fail, not succeed without npm available,.

Distribution Information:

  • OS: Debian
  • Version: Bookworm
  • Base docker image python:3.11-slim-bookworm

Node Version:

  • Node: 20.x

To Reproduce

This Dockerfile will fail with the error npm: not found.

FROM python:3.11-slim-bookworm

RUN apt-get update --fix-missing && apt-get upgrade -y && apt-get dist-upgrade -y

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v

As will this one with the pinning fix.

FROM python:3.11-slim-bookworm

RUN apt-get update --fix-missing && apt-get upgrade -y && apt-get dist-upgrade -y

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN echo "Package: nodejs" >> /etc/apt/preferences.d/preferences
RUN echo "Pin: origin deb.nodesource.com" >> /etc/apt/preferences.d/preferences
RUN echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/preferences
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v

This Dockerfile will succeed - the only difference to the original failure Dockerfile is we're not using the slim version of the base image:

FROM python:3.11-bookworm

RUN apt-get update --fix-missing && apt-get upgrade -y && apt-get dist-upgrade -y

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v

Expected behavior

Either the setup script should have succeeded, and npm be available, or the setup script should have failed (probably complaining about missing build dependencies due to the usage of the slim base image).

Screenshots
N/A

Additional context
N/A

@riosje riosje self-assigned this Mar 26, 2024
@riosje
Copy link
Contributor

riosje commented Mar 26, 2024

Hi @SamStephens.
I tried you Dockerfile but it fails because at first curl is not installed, for that reason
Try installing curl at first :

FROM python:3.11-slim-bookworm

RUN apt-get update -y && apt-get install curl -y
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v

installing

@SamStephens
Copy link
Author

SamStephens commented Mar 26, 2024

Oh okay, that's embarrassing, apologies for the mistake. I was confused here because

curl -fsSL https://deb.nodesource.com/setup_20.x | bash -

Has an exit code of 0, hence Dockerfile execution continues, whereas

curl -fsSL https://deb.nodesource.com/setup_20.x

Has an exit code of 127.

I wonder if there's an alternative way to formulate a command to download and run https://deb.nodesource.com/setup_20.x that will fail if curl is not present?

Especially as this behavior will mask other errors, such as transient 5xx failures, meaning curl -fsSL https://deb.nodesource.com/setup_20.x | bash - isn't really safe in an automated context.

@riosje
Copy link
Contributor

riosje commented Mar 27, 2024

Hi @SamStephens that's why we have the following in the README.

curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs

The apt-get install will not be executed unless the curl returns an exit code 0.
That's what the && operator does.

@riosje riosje closed this as completed Mar 27, 2024
@SamStephens
Copy link
Author

SamStephens commented Mar 27, 2024

@riosje unfortunately the formulation with the && is subject to the same issue.

As I said above, curl -fsSL https://deb.nodesource.com/setup_20.x | bash - has an exit code of 0 when curl is not available. I'm not that deep on shell internals, but it appears the exit code is the zero from the bash that is the pipe destination, not the curl command pipe source with it's 127 exit code.

This is why I formulated things as I did. From a Dockerfile perspective

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs

is functionally equivalent to

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs

with execution being halted before apt-get runs if curl -fsSL https://deb.nodesource.com/setup_20.x | bash - has a non-zero exit code.

You can see this empirically with the Dockerfile

FROM python:3.11-slim-bookworm

RUN apt-get update --fix-missing && apt-get upgrade -y && apt-get dist-upgrade -y

RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs
RUN node -v
RUN npm -v

Which is subject to the same issue as my original reproduction.

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

No branches or pull requests

2 participants