I am using Alpine to build my Rails app and I am having some issues with some of its dependencies.
Right now, here's my Dockerfile:
FROM ruby:2.5.1-alpine
ENV BUNDLER_VERSION=2.0.2
RUN apk add --update --no-cache \
binutils-gold \
build-base \
curl \
file \
g++ \
gcc \
git \
less \
libstdc++ \
libffi-dev \
libc-dev \
linux-headers \
libxml2-dev \
libxslt-dev \
libgcrypt-dev \
make \
netcat-openbsd \
nodejs \
openssl \
pkgconfig \
postgresql-dev \
python \
tzdata \
yarn
RUN gem install bundler -v 2.0.2
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install
COPY . /myapp
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 80
CMD ["rails", "server", "-b", "0.0.0.0", "-p", "80"]
My entrypoint.sh file looks like this:
#!/bin/sh
bundle install
rake db:migrate
rake db:seed
npm install
set -e
rm -f /myapp/tmp/pids/server.pid
exec "$#"
When it comes to npm install, I have issues trying to install puppeteer#3.0.0 (can't use 3.1.0 because of another error).
Here's the error when installing 3.1.0:
/myapp # npm install puppeteer#3.1.0
> puppeteer#3.1.0 install /myapp/node_modules/puppeteer
> node install.js
/myapp/node_modules/puppeteer/install.js:175
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer#3.1.0 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the puppeteer#3.1.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-05-26T01_19_13_984Z-debug.log
Based on the lack of success getting 3.1.0 installed here, I was informed to try 3.0.0
So when trying to install 3.0.0, the following happens:
/myapp # npm install puppeteer#3.0.0
> puppeteer#3.0.0 install /myapp/node_modules/puppeteer
> node install.js
(node:111) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): The "original" argument must be of type function
(node:111) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
+ puppeteer#3.0.0
added 4 packages in 1.264s
According to this, the node version is old. Currently, I am running nodejs 8.9.3, as shown here:
/myapp # node -v
v8.9.3
I tried to install nodejs-current, but it seems like it uninstalled npm.
/myapp # apk add nodejs-current
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/3) Purging nodejs-npm (8.9.3-r1)
(2/3) Purging nodejs (8.9.3-r1)
(3/3) Installing nodejs-current (9.2.1-r1)
Executing busybox-1.27.2-r11.trigger
OK: 300 MiB in 87 packages
/myapp # node -v
v9.2.1
/myapp # npm install puppeteer#3.0.0
/bin/sh: npm: not found
How can I upgrade my nodejs version without uninstalling npm? If I try to install npm again, the following error occurs:
/myapp # apk add npm
ERROR: unsatisfiable constraints:
npm (missing):
required by: world[npm]
/myapp # apk add --update npm
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
npm (missing):
required by: world[npm]
Specify the required version for node like you did with ruby, FROM ruby:2.5.1-alpine , in the Dockerfile or docker-compose.yml file otherwise accordingly.
Check this link for the suitable version.
You need to use the update version of ruby which has the upgraded version of alpine kernel. For an e.g., you can use ruby:2.5.3-alpine3.9
FROM ruby:2.5.3-alpine3.9
ENV BUNDLER_VERSION=2.0.2
RUN apk add --update --no-cache \
binutils-gold \
build-base \
curl \
file \
g++ \
gcc \
git \
less \
libstdc++ \
libffi-dev \
libc-dev \
linux-headers \
libxml2-dev \
libxslt-dev \
libgcrypt-dev \
make \
netcat-openbsd \
nodejs \
npm \
openssl \
pkgconfig \
postgresql-dev \
python \
tzdata \
yarn
RUN gem install bundler -v 2.0.2
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install
and output of few commands
/ # npm -v
6.4.1
/ # node -v
v10.14.2
/ # cat /etc/issue
Welcome to Alpine Linux 3.9
Kernel \r on an \m (\l)
Related
When attempting to run docker build -t app . --memory 3G --memory-swap 4G I run into
Step 8/11 : RUN npm install
---> Running in 5283e1139345
npm WARN deprecated browserslist#2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated fs-promise#2.0.3: Use mz or fs-extra^3.0 with Promise Support
npm WARN deprecated tar.gz#1.0.7: ⚠️ WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
npm ERR! write after end
Does anyone know what causes this error? Why is npm not installing? I'm using aws in conjunction with Docker.
Dockerfile is shown below
FROM ubuntu:18.04
WORKDIR /app
COPY . .
# If you have native dependencies, you'll need extra tools
# RUN apk add --no-cache make gcc g++ python
RUN apt-get update \
&& apt-get install -y --no-install-recommends apt-utils -y \
&& apt-get install curl -y \
&& apt-get install git-core -y \
&& curl -sL https://deb.nodesource.com/setup_8.x \
&& apt-get install -y nodejs npm \
&& curl https://cmake.org/files/v3.11/cmake-3.11.3-Linux-x86_64.sh -o /tmp/curl-install.sh \
&& chmod u+x /tmp/curl-install.sh \
&& mkdir /usr/bin/cmake \
&& /tmp/curl-install.sh --skip-license --prefix=/usr/bin/cmake \
&& rm /tmp/curl-install.sh \
&& apt-get install libpq-dev -y \
&& apt-get install libboost-all-dev -y \
&& apt-get install postgresql-server-dev-all -y
ENV PATH="/usr/bin/cmake/bin:${PATH}"
RUN npm install -g npm#5
RUN ./move-cpp-files.sh
RUN npm install
RUN npm run compile
EXPOSE 3000
CMD ["npm", "start"]
You're potentially installing a version of NPM that had this problem:
RUN npm install -g npm#5
Try without that line or is there a specific reason for it?
I'm trying to run test cases in my node app using Bitbucket pipeline as follows.
image: channagayan/node_test:latest
pipelines:
default:
- step:
caches:
- node
script: # Modify the commands below to build your repository.
- cd NodeApi && pwd && npm install
- npm test
But it fails giving following error
+ cd NodeApi && pwd && npm install
/opt/atlassian/pipelines/agent/build/NodeApi
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t https://git#github.com/peterbraden/node-opencv.git
npm ERR!
npm ERR! fatal: unable to access 'https://git#github.com/peterbraden/node-opencv.git/': Problem with the SSL CA cert (path? access rights?)
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-05-01T09_15_55_789Z-debug.log
My Dockerfile is as follows,
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
build-essential \
cmake \
python-software-properties \
pkg-config \
wget \
&& rm -rf /var/lib/apt/lists/*
#node installation goes here....
RUN apt-get update && apt-get install -y git
#opencv installation goes here....
ENV LD_LIBRARY_PATH /usr/local/lib
WORKDIR /usr/src/app
EXPOSE 3001
It seems like Bitbucket is not accessing the internet from the docker container. Appreciate any help to resolve this.
Trying to run npm install in my docker container. But all I get is this:
pm WARN package.json yeti-ui#0.0.0 No repository field.
npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your operating system or architecture: fsevents#1.1.1
npm ERR! notsup Valid OS: darwin
npm ERR! notsup Valid Arch: any
npm ERR! notsup Actual OS: linux
npm ERR! notsup Actual Arch: x64
npm ERR! System Linux 4.9.31-moby
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! cwd /home/chrome
npm ERR! node -v v4.8.3
npm ERR! npm -v 1.4.21
npm ERR! code EBADPLATFORM
npm WARN prefer global marked#0.3.6 should
And this is how my docker image looks like (i am taking inspiration of a prebuilt:
FROM debian:sid
LABEL name="chrome-headless" \
maintainer="Justin Ribeiro <justin#justinribeiro.com>" \
version="1.4" \
description="Google Chrome Headless in a container"
RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
--no-install-recommends \
&& curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update && apt-get install -y \
google-chrome-stable \
--no-install-recommends \
&& apt-get purge --auto-remove -y curl gnupg \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y nodejs npm git
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN groupadd -r chrome && useradd -r -g chrome -G audio,video chrome \
&& mkdir -p /home/chrome && chown -R chrome:chrome /home/chrome
USER chrome
WORKDIR /home/chrome
ADD .npmrc .npmrc
ADD package.json package.json
COPY . .
# RUN npm install (I have commented this out because the image could not be built for the same reason, so I thought it was easier to debug it if I manually try to run npm install when the container is up and running.)
I have found some forums stating that it might be solved by updating npm. I have tried to update my npm to the latest with this command npm install npm install npm#latest, even though the latest version is being installed it does not seem to use the latest one.
I would like to build this docker image by myself: chrisgeorge/nightmare-headless (https://hub.docker.com/r/chrisgeorge/nightmare-headless/~/dockerfile/)
So I used the same Dockerfile.
Dockerfile
FROM node:slim
RUN apt-get update && \
apt-get install -y \
xvfb \
x11-xkb-utils \
xfonts-100dpi \
xfonts-75dpi \
xfonts-scalable \
xfonts-cyrillic \
x11-apps \
clang \
libdbus-1-dev \
libgtk2.0-dev \
libnotify-dev \
libgnome-keyring-dev \
libgconf2-dev \
libasound2-dev \
libcap-dev \
libcups2-dev \
libxtst-dev \
libxss1 \
libnss3-dev \
gcc-multilib \
g++-multilib \
xauth \
git \
sudo \
--no-install-recommends \
&& apt-get autoclean \
&& apt-get clean \
&& rm -rf /var/lib/api/lists/*
RUN chown -R node:node /home/node
RUN echo %sudo ALL=NOPASSWD: ALL >> /etc/sudoers
WORKDIR /home/node
ENV HOME /home/node
USER node
RUN npm install nightmare
npm install nightmare will call npm install electron and this is failing:
/usr/local/lib/node_modules/electron/install.js:47
throw err
^
Error: ENOENT: no such file or directory, lstat '/usr/local/lib/node_modules/electron/dist/resources'
at Error (native)
npm ERR! Linux 4.4.0-72-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "electron"
npm ERR! node v6.10.2
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! electron#1.6.6 postinstall: `node install.js`
npm ERR! Exit status 1
Generally speaking this happens because the versions of the dependencies in the dockerfile are not specified.
An application can break if its dependencies have a different version than what it was developed with. It's best practice to set the version of most dependencies in the dockerfile so that apt install actually installs the same software all the time. Some exceptions exist like curl used for a healthcheck which will almost 100% work after an update too
Update: this should now be fixed - https://github.com/electron/electron/issues/9323#issuecomment-298287399
This is a bug in a dependency of Electron, there is a workaround:
add "extract-zip": "=1.6.0", to your project's package.json dependencies in the same place where electron dependency located.
I am running a node web service inside docker container.
When I run Docker container with entrypoint
CMD ["node", "app.js"]
it gives me the below mentioned error.
When I use
CMD /bin/bash
and enter the contianer and run node app.js then my application works fine
This is the error:
Error: Module did not self-register.
at Error (native)
at Object.Module._extensions..node (module.js:435:18)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at bindings (/usr/src/app/controlcenter/node_modules/bindings/bindings.js:76:44)
at Object.<anonymous> (/usr/src/app/controlcenter/node_modules/couchbase/lib/binding.js:143:36)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/usr/src/app/controlcenter/node_modules/couchbase/lib/couchbase.js:3:15)
at Module._compile (module.js:410:26)
node version v0.10.37
npm -version 1.4.28
nvm --version 0.33.0
My entire Dockerfile:
FROM ubuntu:16.04
RUN mkdir -p /usr/src/app/controlcenter
WORKDIR /usr/src/app/controlcenter
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils \
build-essential \
apt-transport-https \
build-essential \
wget \
curl \
vim \
python
RUN \
apt-get -y install software-properties-common && \
add-apt-repository ppa:openjdk-r/ppa && \
apt-get update && \
apt-get install -y openjdk-7-jdk && \
rm -rf /var/lib/apt/lists/
RUN wget http://nodejs.org/dist/v4.2.6/node-v4.2.6.tar.gz -P /tmp/ && \
tar xvzf /tmp/node-v4.2.6.tar.gz && cd node-v* && \
./configure && \
make && \
make test && \
make install
COPY . /usr/src/app/controlcenter/
ENV NVM_DIR "$HOME/.nvm"
ENV JAVA_HOME /usr/lib/jvm/openjdk-7-jdk
RUN npm install sails -g \
&& npm install grunt-cli -g \
&& npm install jsonlint-lines -g \
&& npm install node-ninja -g
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash \
&& /bin/sh "$NVM_DIR/nvm.sh" \
&& . "$NVM_DIR/nvm.sh" \
&& nvm install 0.10.37 \
&& nvm use 0.10.37 \
&& npm install jdbc \
&& rm -rf node_modules/couchbase/ \
&& npm install couchbase\
&& nvm alias default 0.10.37
EXPOSE 1337
CMD ["node", "app.js"]
It seems that you are copying the whole application directory into the docker image, with the node_modules directory. This npm install was executed with your local node version (v0.10.37) and you are installing another one in your container (v4.2.6) so maybe this is the problem.
I recommend you to remove your node_modules directory and execute the npm install command in your Dockerfile.
So:
Go to your application directory in your host and execute:
rm -rf node_modules
Add a layer in your Dockerfile to do the npm install command after the copy one.
...
COPY . /usr/src/app/controlcenter/
RUN npm install
...
Run the container again.