npm install failing in alpine based docker image - node.js

I'm trying to run a node server in an Alpine based Docker image. However, it's failing on npm install. I would appreciate some help in figuring out what the issue is. Here is the Dockerfile
Here is the error when 'npm install' tries to run

One of your project depedencies requires an X window development package libXext which is not being install in your apk add... command.
Add the libxext-dev Alpine package, for instance.

Related

Yarn command "develop" not found

For reference, the goal is to design a blog website on github using .mdx format.
I'm trying to run a prebuilt docker container (I did not compose the image) using an M1 Mac. For ambiguity's sake - let's say the container image is called "docker run -it -p "8881:8000" -v "$PWD:/app" "xxxxxxxx/yyy-zzz-purpose-of-container". One of the container dependencies is yarn, as can be seen from the output. Also, the yarn command "develop" is erroring as not found. Aside from the seemingly inocuous license output, the CLI displays:
warning package.json: No license field error Command "develop" not found.
I then tried to run it natively without the docker image as a node.js sequence of commands, and received the same error.
nvm install --lts="Gallium"
nvm alias default 'lts/Gallium'
npm install -g npm
npm install -g gatsby-cli
npm install -g yarn
yarn install .
yarn run develop
I get the same error as with the container.

Dependencies from Docker image not found in the running container

Background
So I'm trying to set up a Docker container for development, and one of my dependencies is webpack.
Repo Steps:
install this in the image with an npm install webpack.
The image builds successfully
I run it
In the Docker Desktop GUI shell I type webpack -v
Then get output webpack: command not found.
Question
How does it not find the command if it was one of the dependencies installed on the base image?

Unable to install "testmybot" npm package

I am trying to use this sample to demonstrate the chatbot testing using node "testmybot" package. When I execute "npm install" command I am getting error. Please find the screenshot of the same attached below.
Steps that I have followed:
1. Downloaded the project from [https://github.com/codeforequity-at/testmybot-sample-calculator]
2. Extracted the project to "testmybot-sample-calculator-master" folder
3. Inside the folder executed "npm install" command
4. After installing some packages, looks like while installing botkit package it is throwing error
Please let me know if I have missed out any steps.
To run this sample, there is now a Dockerfile included in the Github repository. The following commands should retrieve the latest files from Github, build a docker container and running the sample test cases inside.
$ git pull
$ docker build -t testmybot-sample-calculator .
$ docker run testmybot-sample-calculator
Obviously, you have to install docker first.
UPDATE:
I was able to reproduce it on a Windows workstation, user had no admin rights. Found solution here: you have to install the windows-build-tools package first, with a user having admin rights:
npm install --global --production windows-build-tools
Afterwards, installation of the package in question was possible.

cannot build docker image

I have been trying to build a Docker image by using this Dockerfile:
FROM mhart/alpine-node:base-6
MAINTAINER techhadmin
COPY ./package.json src/
RUN cd src && npm install
COPY . /src
WORKDIR /src
EXPOSE 3000
CMD ["npm", "start"]
But I receive this error:
/bin/sh: npm: not found
The command '/bin/sh -c cd src && npm install' returned a non-zero code: 127
Any idea how I can solve this?
Read the docs:
https://hub.docker.com/r/mhart/alpine-node/
Is written:
# If you need npm, don't use a base tag
# RUN npm install
So don't use base-6 tag and change FROM image to something like 7
FROM mhart/alpine-node:7
You are seeing this error message because when you tried to run npm install, there is no copy of npm available.
You are using alpine as the base image.
By default, alpine is a small image and so it has a limited set of default programs inside of it. What programs are in the alpine image? Not much.
So if you are trying to run an alpine image with Nodejs you need to do additional work.
To solve it, you have two options:
Find a different base image. - You can try to find a base image that already has Node and NPM inside of it.
Run alpine with some additional commands that attempts to install npm inside of it.
Use someone else's work or building it from scratch.
I recommend finding an image preconfigured with npm inside of it. You can navigate to DockerHub, which is a repository of images.
There is an official Node repository in DockerHub.
https://hub.docker.com/_/node
So you could do something like this:
# Specify base image
FROM node:alpine
# Install some dependencies
RUN npm install
# Setup default command
CMD ["npm", "start"]
The nice thing about node:alpine is that you will not get any additional unnecessary packages, just the absolute stripped down version of Nodejs and nothing else aside from the basics such as the ping command, cat, ls and so on.

How can you get Grunt livereload to work inside Docker?

I'm trying to use Docker as a dev environment in Windows.
The app I'm developing uses Node, NPM and Bower for setting up the dev tools, and Grunt for its task running, and includes a live reload so the app updates when the code changes. Pretty standard. It works fine outside of Docker but I keep running into the Grunt error Fatal error: Unable to find local grunt. no matter how I try to do it inside Docker.
My latest effort involves installing all the npm and bower dependencies to an app directory in the image at build time, as well as copying the app's Gruntfile.js to that directory.
Then in Docker-Compose I create a Volume that is linked to the host app, and ask Grunt to watch that volume using Grunt's --base option. It still won't work. I still get the fatal error.
Here are the Docker files in question:
Dockerfile:
# Pull base image.
FROM node:5.1
# Setup environment
ENV NODE_ENV development
# Setup build folder
RUN mkdir /app
WORKDIR /app
# Build apps
#globals
RUN npm install -g bower
RUN echo '{ "allow_root": true }' > /root/.bowerrc
RUN npm install -g grunt
RUN npm install -g grunt-cli
RUN apt-get update
RUN apt-get install ruby-compass -y
#locals
ADD package.json /app/
ADD Gruntfile.js /app/
RUN npm install
ADD bower.json /app/
RUN bower install
docker-compose.yml:
angular:
build: .
command: sh /host_app/startup.sh
volumes:
- .:/host_app
net: "host"
startup.sh:
#!/bin/bash
grunt --base /host_app serve
The only way I can actually get the app to run at all in Docker is to copy all the files over to the image at build time, create the dev dependencies there and then, and run Grunt against the copied files. But then I have to run a new build every time I change anything in my app.
There must be a way? My Django app is able to do a live reload in Docker no problems, as per Docker's own Django quick startup instructions. So I know live reload can work with Docker.
PS: I have tried leaving the Gruntfile on the Volume and using Grunt's --gruntfile option but it still crashes. I have also tried creating the dependencies at Docker-Compose time, in the shared Volume, but I run into npm errors to do with unpacking tars. I get the impression that the VM can't cope with the amount of data running over the shared file system and chokes, or maybe that the Windows file system can't store the Linux files properly. Or something.

Resources