2

I'm trying to create a Docker container running node.js on Amazon Linux to allow native node modules to compile on machine in a suitable form for AWS Lambda.

I'm primarily following this tutorial on The Polyglot Developer, but have also tried one on the AWS Blogs. I am attempting to build the container with the following command in the Dockerfile's parent directory.

docker build -t amazonlinux-node8 .

Steps 1 & 2 complete succesfully but on step 3 throws the following error.

/root/.nvm/nvm.sh: ... tar: command not found

It then exits with the following message.

The command '/bin/sh -c /bin/bash -c "source /root/.nvm/nvm.sh; nvm install 8.10.0"' returned a non-zero code: 1

What changes do I need to make to fix this error?

Dockerfile

FROM amazonlinux:latest

RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

RUN /bin/bash -c "source /root/.nvm/nvm.sh; nvm install 8.10.0"

CMD /bin/bash -c "source /root/.nvm/nvm.sh; nvm use 8.10.0"

I have tried the solution suggested on this SO post by adding steps to download tar.x86_64 but this fails and will not install on the amazonlinux image. I have seen another suggested solution on this post, however it specifically relates to use of the COPY command in the Dockerfile which is not applicable to my file.

Josh
  • 1,517
  • 1
  • 13
  • 21
  • 1
    I’d just start my Dockerfile `FROM node:8`. I would not try to use a version manager like nvm in a Docker image: you never need more than one version of Node in a single image and the setup is slightly tricky. – David Maze Feb 20 '19 at 20:42
  • Thanks, I'd had the same thought as it seems like the obvious option. My doubt was that the `node:8` image would not be using a suitable OS to solve the compilation issue. If it does then these tutorials offer an absurd solution. In any case I have since discovered the `lambci/lambda:build-nodejs8.10` (https://hub.docker.com/r/lambci/lambda) which solves my issue perfectly. – Josh Feb 21 '19 at 11:00

0 Answers0