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

Import fails when using node alpine docker image #21

Open
dyc3 opened this issue Apr 19, 2020 · 8 comments
Open

Import fails when using node alpine docker image #21

dyc3 opened this issue Apr 19, 2020 · 8 comments

Comments

@dyc3
Copy link

dyc3 commented Apr 19, 2020

I'm using the docker image node:alpine3.11 to build and deploy my application.

internal/modules/cjs/loader.js:1197
 return process.dlopen(module, path.toNamespacedPath(filename));

Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/app/node_modules/sodium-native/prebuilds/linux-x64/libsodium.so.23)
 at Object.Module._extensions..node (internal/modules/cjs/loader.js:1197:18)
 at Module.load (internal/modules/cjs/loader.js:996:32)
 at Function.Module._load (internal/modules/cjs/loader.js:896:14)
 at Module.require (internal/modules/cjs/loader.js:1036:19)
 at require (internal/modules/cjs/helpers.js:72:18)
 at load (/usr/app/node_modules/node-gyp-build/index.js:21:10)
 at Object.<anonymous> (/usr/app/node_modules/sodium-native/index.js:1:39)
 at Module._compile (internal/modules/cjs/loader.js:1147:30)
 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
 at Module.load (internal/modules/cjs/loader.js:996:32)
@emilbayes
Copy link
Owner

Hi, it seems like your docker image failed to load the correct binary. Can you share more of your Dcokerfile?

You might have this issue: sodium-friends/sodium-native#126

@dyc3
Copy link
Author

dyc3 commented Apr 20, 2020

Sure, its in a PR for one of my projects: dyc3/opentogethertube#209 commit ddc38da

This is what the docker file looks like

### Build stage ###
FROM node:alpine3.11 as build-stage

# Create app directory
WORKDIR /usr/app

# Copy the important file
COPY . .

# Install app dependencies
RUN npm install

# Build the application for deployement
RUN npm run build


### Deployement server nginx ###
FROM node:alpine3.11 as production-stage

# Create app directory
WORKDIR /usr/app/

# Environnement variable redis/postgres/webport
ENV REDIS_PORT 6379
# Environnement variable nodejs
ENV NODE_ENV production
ENV PORT 8080

# Install sqlite3
RUN apk update -q
RUN apk add sqlite curl -q

# Copy from build stage
COPY --from=build-stage /usr/app/ /usr/app/
COPY --from=build-stage /usr/app/docker/scripts/wait_for_db.sh /usr/app/wait_for_db.sh

# Install app dependencies
RUN npm install --production

# Remove all the unnecessary directories
RUN rm -rf docker .github .vscode db public test src

# Remove all the unnecessary files
RUN rm -rf env .browserslistrc .eslintrc.js .gitignore .travis.yml codecov.yaml
RUN rm -rf jest.config.js postcss.config.js vue.config.js babel.config.js docker-compose.yml

RUN mkdir env && touch env/production.env 

# Healthcheck API, WEB, REDIS
HEALTHCHECK CMD ( curl -f http://localhost:8080/ || exit 1 )

# Start Server
CMD ["/bin/sh", "wait_for_db.sh", "postgres_db:5432", "--", "npm", "run", "start"]

@emilbayes
Copy link
Owner

Did you see the other issue I linked? I'm not too familiar with docker build stages

@dyc3
Copy link
Author

dyc3 commented Apr 20, 2020

After adding the line

RUN apk --update add --no-cache curl git python alpine-sdk bash autoconf libtool automake

It still fails with the same error.

@emilbayes
Copy link
Owner

@dyc3 what stage did you add it to?

@emilbayes
Copy link
Owner

And what node version is that running?

@dyc3
Copy link
Author

dyc3 commented Apr 21, 2020

The node:alpine3.11 tag runs the latest version of node (13.13.0) on alpine 3.11

@marcbachmann
Copy link
Contributor

marcbachmann commented Apr 5, 2021

This might be helpful to others.
I'm using the following Dockerfile instructions using alpine linux.
The environment variable helps in finding the prebuilt version:

FROM node:15-alpine
RUN apk add --no-cache --virtual build-deps python alpine-sdk autoconf libtool automake && \
  mkdir -p /prebuilds && cd /prebuilds && npm init -y && npm install sodium-native@3.1.1 && \
  apk del build-deps
ENV SODIUM_NATIVE_PREBUILD=/prebuilds/node_modules/sodium-native/

and a new version with node 16 (includes python3 instead of python2):

FROM node:16-alpine
RUN apk add --no-cache --virtual build-deps python3 alpine-sdk autoconf libtool automake && \
  mkdir -p /prebuilds && cd /prebuilds && npm init -y && npm install sodium-native@3.1.1 && \
  apk del build-deps
ENV SODIUM_NATIVE_PREBUILD=/prebuilds/node_modules/sodium-native/

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

3 participants