gulp not running in Dockerfile: Local gulp not found in / - docker

This is my Dockerfile:
RUN mkdir /mcvitty
COPY . /mcvitty
RUN cd /mcvitty &&\
npm install -g gulp#3.9.1 &&\
npm link gulp --force &&\
npm install jshint#2.9.5 &&\
npm install gulp-jshint#2.0.4 &&\
npm install gulp-sass#3.1.0 &&\
npm install gulp-concat#2.6.1 &&\
npm install gulp-uglify#3.0.0 &&\
npm install gulp-rename#1.2.2 &&\
npm install gulp-minify-css#1.2.4 &&\
npm install gulp-image-resize#0.13.0
RUN gulp
RUN gulp resize-images
Whenever I run my container I get the following error:
[08:35:34] Local gulp not found in /
[08:35:34] Try running: npm install gulp
The command '/bin/sh -c gulp' returned a non-zero code: 1
Adding
npm install gulp#3.9.1
to have a local gulp, as suggested by someone does not work either.
Any suggestion?

I have Gulp running in a container. The main differences are that I set a working directory:
RUN mkdir /mcvitty
WORKDIR /mcvitty
COPY . /mcvitty
I don't run npm link gulp, either.
If that doesn't work, remove the RUN gulp commands and add them to your docker run command, e.g.
docker run -it --rm --entrypoint '/bin/sh' myimage -c 'gulp && gulp images'

I fixed the problem by CD back into my dir before running gulp:
RUN cd /mcvitty && gulp

Related

Installed packages in docker image not found in path?

My Dockerfile for custom image with Gradle and Node installed:
FROM ubuntu:jammy
LABEL key=DevOps
SHELL ["/bin/bash", "--login", "-i", "-c"]
RUN apt update && apt upgrade -y && apt install curl -y
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
RUN source /root/.bashrc && nvm install 12.14.1
RUN nvm install 12.20.0
RUN apt install zip unzip
RUN curl -s "https://get.sdkman.io" | bash
RUN source "$HOME/.sdkman/bin/sdkman-init.sh"
RUN sdk install java 8.0.302-open
RUN sdk install gradle 3.4.1
SHELL ["/bin/bash", "--login", "-c"]
CMD [ "bin/bash" ]
After I run it, it says that npm is not found in $PATH, I tried Java, Gradle as well but they weren't found in the path as well.
I don't know why since I installed them as you can tell from the Dockerfile.
How can I preinstall these dependencies so that I can address them during the build process of my app?

/root/start.sh: line 5: /usr/bin/pm2: No such file or directory - Docker Container is restarting

I'm trying to run on my Ubuntu 20.04 machine a cluster of docker containers present in this repository :
https://github.com/Capgemini-AIE/ethereum-docker
My dockerfile:
FROM ethereum/client-go
RUN apk update && apk add bash
RUN apk add --update git bash nodejs npm perl
RUN cd /root &&\
git clone https://github.com/cubedro/eth-net-intelligence-api &&\
cd eth-net-intelligence-api &&\
npm install &&\
npm install -g pm2
ADD start.sh /root/start.sh
ADD app.json /root/eth-net-intelligence-api/app.json
RUN chmod +x /root/start.sh
ENTRYPOINT /root/start.sh
The commands:
sudo docker-compose build
sudo docker-compose up -d
are done correctly, but when execute:
docker exec -it ethereum-docker-master_eth_1 geth attach ipc://root/.ethereum/devchain/geth.ipc
i have this error:
ERROR: Container 517e11aef83f0da580fdb91b6efd19adc8b1f489d6a917b43cc2d22881b865c6 is restarting, wait until the container is running
The reason is, executing:
docker logs ethereum-docker-master_eth_1
result:\
/root/start.sh: line 5: /usr/bin/pm2: No such file or directory\
/root/start.sh: line 5: /usr/bin/pm2: No such file or directory\
/root/start.sh: line 5: /usr/bin/pm2: No such file or directory
Why do I have this problem? In the Docker file I have the command:
RUN npm install -g pm2
How can I solve the problem?
When I build an image with this dockerfile and then check the files in it I find that pm2 is installed at /usr/local/bin/pm2:
So you need to change the call in your script to
/usr/local/bin/pm2

Npm install specific version does not work in Dockerfile

I'm trying to install a specific version of npm package within the node:alpine image (latest tag), so this is what I specified in my Dockerfile:
Edit (this is the full Dockerfile):
FROM node:alpine as build-stage
ARG SONAR_VERSION=4.6.0.2311
RUN apk add --no-cache zip unzip
RUN wget -c https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_VERSION-linux.zip
RUN unzip -q sonar-scanner-cli-$SONAR_VERSION-linux.zip
RUN rm sonar-scanner-cli-$SONAR_VERSION-linux.zip
# Adding the $install_directory/bin directory to path
RUN cd sonar-scanner-$SONAR_VERSION-linux
RUN echo $PWD
RUN export PATH="$PATH:/$PWD/bin"
RUN npm i -g eslint#6.7.2
RUN npm i -g eslint-plugin-vue --save-dev
However when I run & execute the built image, the installed version of eslint is the latest instead of what I'd specified in the Dockerfile.
Result from npm list -g:
/ # npm list -g
/usr/local/lib
+-- eslint-plugin-vue#7.9.0
+-- eslint#7.25.0
`-- npm#7.11.2
If I run npm i -g eslint#6.7.2 within the container itself, the version from npm list -g will be exactly the one I specified.
What is the reason of this scenario?

How to speed up RUN npm in Dockerfile

I have all this npm stuff in my Dockerfile and it is taking a long time to build my docker image. How can I speed this up, and ideally cache the results? Nothing is changing, so I wouldn't expect this to take such a long time (about 20 seconds now).
FROM python:3.6-alpine
# python stuff
COPY requirements.txt /app/requirements.txt
RUN pip3 install --upgrade pip
RUN pip3 install -r /app/requirements.txt
# npm stuff
RUN apk add --update nodejs-npm
RUN npm init -y
RUN npm i webpack webpack-cli --save-dev
RUN npm i #babel/core babel-loader #babel/preset-env #babel/preset-react babel-plugin-transform-class-properties --save-dev
RUN npm i react react-dom prop-types --save
RUN npm i react-bootstrap bootstrap
RUN npm i weak-key --save
I did try this solution using the COPY package.json but babel and webpack did not seem to like that (and it did not work).
NOTE: I need to use python:3.6-alpine as this is an existing Django application that is integrating React.js

how to run gulp task from dockerfile

I am trying to run gulp task from my Dockerfile. Here is my Dockerfile
#
# Node.js w/ Bower & Grunt Dockerfile
#
# https://github.com/digitallyseamless/docker-nodejs-bower-grunt
#
# Pull base image.
FROM library/node:4
MAINTAINER Digitally Seamless <docker#digitallyseamless.com>
# Install Bower & Grunt
RUN npm install -g bower grunt-cli && \
echo '{ "allow_root": true }' > /root/.bowerrc
RUN npm install gulp -y
RUN gulp ng-config --env development
# Define working directory.
WORKDIR /data
COPY . /data
# Define default command.
EXPOSE 7000
CMD ["bash"]
Please note in above Dockerfile I am trying to install gulp and run gulp task as follows:
RUN npm install gulp -y
RUN gulp ng-config --env development
where ng-config is my gulp task defined in gulpfile.js file.
when I try to build image with above mentioned Dockerfile content I get error like gulp: not found
I am not sure if gulp is not getting installed properly or why it is not recognizing the gulp command.
Can you guys please help?
EDIT:
If I try to install gulp globally, my build fails with following output.
Sending build context to Docker daemon 7.893MB
Step 1/9 : FROM library/node:4
---> 3fb5ca8fcd8e
Step 2/9 : MAINTAINER Digitally Seamless <docker#digitallyseamless.com>
---> Using cache
---> 242154cec3ce
Step 3/9 : RUN npm install -g bower grunt-cli && echo '{ "allow_root": true }' > /root/.bowerrc
---> Using cache
---> b73fc7831a4a
Step 4/9 : RUN npm install -g gulp -y
---> Using cache
---> b498e61bfb8e
Step 5/9 : RUN gulp ng-config --env development
---> Running in 38d2e7f208cc
[08:21:29] Local gulp not found in /
[08:21:29] Try running: npm install gulp
The command '/bin/sh -c gulp ng-config --env development' returned a non-zero code: 1
You have to install gulp globally AND locally:
RUN npm install -g gulp
RUN npm install gulp
See this post for a discussion about the reason.

Resources