Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beatfactor/e3b285fddae95cc0b63469655b1e9adb to your computer and use it in GitHub Desktop.
Save beatfactor/e3b285fddae95cc0b63469655b1e9adb to your computer and use it in GitHub Desktop.
Running serialport in Docker with node alpine

When attempting to build the awesome serialport NPM package in Docker using a node alpine image, in usually failes on building the node-gyp package.

There are various workarounds which can be found online, such as this one.

However, the key ingredient is building the serialport package from source, using this line:

npm install serialport --build-from-source=serialport

Here's the full Dockerfile:

FROM node:12-alpine
WORKDIR /app/
COPY ./package*.json .
####
# copy the rest of your app
####
RUN apk add --no-cache --virtual .gyp \
python \
make \
linux-headers \
udev \
g++ \
&& npm install serialport --build-from-source \
&& npm install --production \
&& apk del .gyp
USER node
CMD ["node", "app.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment