0

I'm trying to build a minimal node.js docker image. I have compiled node on my Debian system, it installs/works well. Correct me if I'm wrong, to my understanding it should be enough of copying node.js binaries and their dependencies so it should work on the other system.

Currently I have cooked the following script:

#! /bin/bash
# Build Node as the first step in '/opt/node'.
# Then use this script to install Node to the
# custom directory '/opt/node_tmp' and package
# it to *.tar.gz archive.

set -e

BLD_PATH='/opt/node'
TMP_PATH='/opt/node_tmp'

mkdir -p "${TMP_PATH}"

pushd "${BLD_PATH}"

command python tools/install.py install '' "${TMP_PATH}"

popd

VERSION=$("${TMP_PATH}/bin/node" --version)

# Package Node
tar -Pczf "node_${VERSION}.tar.gz" -C "${TMP_PATH}" .

DEPS=$(ldd "${TMP_PATH}/bin/node" | awk '{for(x=1;x<=NR;x++){if($x~"/"){print $x}}}')

# Package Node dependencies
tar -Pvczf "node_${VERSION}_depends.tar.gz" ${DEPS}

du -sh "node_${VERSION}.tar.gz"
du -sh "node_${VERSION}_depends.tar.gz"

echo "About to delete '${TMP_PATH}', continue?"
select yn in "Yes" "No"; do
  case $yn in
    ([Yy]*)
      rm -vrf "${TMP_PATH}"
      break
    ;;
    (*) break ;;
  esac
done

And the following Dockerfile:

FROM busybox:latest
MAINTAINER narunask

ARG img="Node"
ARG version="v5.12.0"

## Install Node
ADD node_${version}.tar.gz /usr/local/
ADD node_${version}_depends.tar.gz /

My Docker session looks like the following:

/ # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/ # ls -l /usr/local/bin
total 18864
-rwxr-xr-x    1 root     root      19313296 Mar 22 15:18 node
lrwxrwxrwx    1 root     root            38 Mar 24 16:35 npm -> ../lib/node_modules/npm/bin/npm-cli.js
/ # /usr/local/bin/node --version
/bin/sh: /usr/local/bin/node: not found
/ # node --version
/bin/sh: node: not found

Would appreciate some help.

NarūnasK
  • 368
  • 4
  • 17

1 Answers1

1

Correct me if I'm wrong, to my understanding it should be enough of copying node.js binaries and their dependencies so it should work on the other system.

No, you need to build Node and its dependencies for the specific system that you're going to run it on. Moving binaries from Debian to a stripped down Busybox image is unlikely to work, unless you move half of teh Debian system libraries along with it, and even then only if everything else is compatible like the kernel, libc, etc.

See the Docker files for Node:

And look for the ones based on Alpine, as those would be the most lightweight.

rsp
  • 241
  • 1
  • 4