Docker NPM Install Not working - asp.net

I want to expose my asp.net core application in docker. However i can't get NPM to work. I tried the following below but i get the message that NPM is not found. However i installed nodejs, so i guess it should be available.
Any idea what i'm doing wrong ?
FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr
ADD package.json /tmp/package.json
RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
RUN apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update
RUN apt-get -y install nodejs && cd /tmp && npm install
COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]
EXPOSE 5001/tcp
ENTRYPOINT ["dnx", "-p", "project.json", "web"]

Older versions of Node did not have npm bundled with them. On some Linux distributions, the version of Node in the repository is quite old e.g. on centos it is something like 0.10.7.
It is likely that your application requires a certain version of nodejs to be installed. If this is so, you will need to add the relevant repository to your virtual machine as part of the dockerfile before running
apt-get -y install nodejs
This link gives some details of how to do this on your distribution:
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions.
If on the other hand you are happy with whatever version of Node your distribution has in its repo, then Suresh Koya's answer is fine.

On linux npm has to be installed separate than nodejs.
You need to add:
RUN apt-get -y install npm
http://blog.teamtreehouse.com/install-node-js-npm-linux

As you can see here:
https://hub.docker.com/r/microsoft/aspnet/~/dockerfile/
FROM mono:4.0.1
mono:4.0.1:
FROM debian:wheezy
Why do you use the jessie ?
RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
FROM microsoft/aspnet:1.0.0-rc1-update1-coreclr
ADD package.json /tmp/package.json
RUN printf "deb http://ftp.us.debian.org/debian jessie main\n" >> /etc/apt/sources.list
RUN apt-get -qq update && apt-get install -qqy sqlite3 libsqlite3-dev && \
apt-get -y install nodejs npm && cd /tmp && npm install && \
rm -rf /var/lib/apt/lists/*
COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]
EXPOSE 5001/tcp
ENTRYPOINT ["dnx", "-p", "project.json", "web"]

Related

Creating Docker with Ruby and R

I have a rails application that combines some R code. It works fine, and now is the time to dockerize it. I tried creating the docker based on a ruby image, which failed installing R properly, and then the other way around (R image, installing ruby using rbenv as explained here) which failed too.
Has anyone experienced with this combo?
EDIT: I have managed to create a docker using the R image, however this requires a tiring installation of many ruby dependencies. So consider this side done.
Still, why won't the other way (installing R on ruby image) work?
Ruby-based:
FROM ruby:2.7.1 AS rails-toolbox
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /app
WORKDIR /app
ADD shalev/Gemfile /app/Gemfile
ADD shalev/Gemfile.lock /app/Gemfile.lock
RUN bundle install --without development test doc --jobs=4
RUN apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https
RUN wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
RUN echo "deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/" | tee -a /etc/apt/sources.list
RUN apt-get update
RUN apt-get install r-base
COPY shalev/ /app/
[...]
error message:
Step 13/20 : RUN apt-get install r-base
---> Running in f546cfe57d33
Reading package lists...
Building dependency tree...
Reading state information...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
r-base : Depends: r-base-core (>= 3.6.3-1bionic) but it is not going to be installed
Depends: r-recommended (= 3.6.3-1bionic) but it is not going to be installed
Recommends: r-base-html but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
The command '/bin/sh -c apt-get install r-base' returned a non-zero code: 100
R-based:
FROM rocker/r-ver:3.6.3
RUN apt-get update -qq && apt-get install -y apt-utils apt-transport-https build-essential libpq-dev nodejs
RUN apt-get install -y git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn curl bzip2
RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv \
&& echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc \
&& echo 'eval "$(rbenv init -)"' >> ~/.bashrc
ENV HOME /home/shalev
ENV PATH "$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
ENV RUBY_VERSION 2.7.1
RUN mkdir -p "$(rbenv root)"/plugins \
&& git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
RUN rbenv install $RUBY_VERSION
RUN rbenv global $RUBY_VERSION && rbenv versions && ruby -v
RUN mkdir /app
[...]
error message:
Step 9/25 : RUN rbenv install $RUBY_VERSION
---> Running in 9939299d6ed1
/bin/sh: 1: rbenv: not found
You can use the stand alone version of ruby-build.
Note that you are root and not shalev inside the container:
FROM rocker/r-ver:3.6.3
RUN apt-get update -qq && \
apt-get install -y \
apt-utils apt-transport-https \
build-essential libpq-dev nodejs
RUN apt-get install -y \
git-core zlib1g-dev build-essential \
libssl-dev libreadline-dev libyaml-dev \
libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev \
libcurl4-openssl-dev software-properties-common \
libffi-dev nodejs yarn curl bzip2
RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv \
&& echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc \
&& echo 'eval "$(rbenv init -)"' >> ~/.bashrc
ENV PATH "/root/.rbenv/bin/:/root/.rbenv/shims/:$PATH"
ENV RUBY_VERSION 2.7.1
RUN git clone https://github.com/rbenv/ruby-build.git && \
PREFIX=/usr/local ./ruby-build/install.sh
RUN rbenv install $RUBY_VERSION && \
rbenv global $RUBY_VERSION && \
rbenv versions
RUN mkdir /app
I managed to make it work with the ruby image as well:
FROM ruby:2.7.1 AS rails-toolbox
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN apt-get install -y apt-utils apt-transport-https
RUN apt-get install -y gfortran
RUN wget -c https://cran.r-project.org/src/base/R-3/R-3.6.3.tar.gz
RUN tar -xf R-3.6.3.tar.gz
WORKDIR "/R-3.6.3"
RUN ./configure
RUN make -j9
RUN make install
WORKDIR "/root"
RUN mkdir /app
[...]

How to install a specific version of node in a Ubuntu environment

When I docker run -it wordpress:php7.0-apache I could execute all of those following command
FROM wordpress:php7.0-apache
RUN apt-get update
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
RUN /bin/dash ~/.profile
RUN /bin/dash nvm install 8.11.4
My issue is when I try to docker build -t imageName:version I would have an error :
/bin/dash: 0: Can't open nvm
The command '/bin/sh -c /bin/dash nvm install 8.11.4' returned a non-zero code: 1277
What could be the difference ?
Thank you David Maze. Indeed there is no need of nvm to install a specific version.
My Dockerfile now :
FROM wordpress:php7.0-apache
RUN apt-get update && apt-get install -y gnupg gnupg2 gnupg1
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs

Docker + Angular2 + ASP.NET Core build errors

I'm trying to build a Docker Image from my Angular2 App that runs on ASP.Net Core. I've used the Dockerfile from https://github.com/MarkPieszak/aspnetcore-angular2-universal/blob/master/Dockerfile to create my Dockerfile and it almost works except for folloing error showing up when I run the image I created:
Uncaught ReferenceError: vendor_ is not defined
Therefor I assumed that the problem lies within webpack and added the following code:
RUN webpack --config webpack.config.vendor.js
But now I'm getting this error:
/bin/sh: 1: webpack: not found
After that I tried:
RUN npm install webpack -g
RUN npm install webpack-cli -g
But that keeps failing with cryptic errors like:
Error: Cannot find module 'js.clone'
That's the Dockerfile I copied for my Dockerfile and to what I added the aformentioned lines of Code:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
RUN apt-get -qq update && apt-get install -y build-essential
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
RUN npm i -g --unsafe-perm node-sass && npm rebuild --unsafe-perm node-sass -f
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY Asp2017.csproj .
RUN apt-get -qq update && apt-get install build-essential -y && apt-get install -my wget gnupg && apt-get -qq -y install bzip2
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
RUN dotnet restore ./Asp2017.csproj
COPY . .
WORKDIR /src/
RUN dotnet build Asp2017.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish Asp2017.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Asp2017.dll"]
So my question is:
What is best practice for a Dockerfile for Angular2 + ASP.NET Core?
Thanks for any ideas and help!
For anyone else facing similar problems: I actually only managed to get this to work by running webpack and dotnet publish -c Release -o out before docker build ....
The new Dockerfile looks like this:
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY out .
EXPOSE 7000/tcp
ENTRYPOINT ["dotnet", "myApp.dll"]
Hope it helps!

Docker install nginx

I new with docker and want to install nginx inside my container for redirection on external ip
my goal is send request to http://localhost:3010/api/v1/service
inside docker and it should redirect me to my http://192.168.99.1:3010/api/v1/service
http://192.168.99.1:3010 -it my rails server running
Or maybe i totally wrong with my idea?
i try to do it RUN yum install nginx but i have got
ERROR: Service 'my_service_name' failed to build: The command '/bin/sh -c yum install nginx' returned a non-zero code: 1
dockerfile
FROM jboss/wildfly:latest
USER root
ENV TERM dumb
RUN yum -y install wget && \
wget https://github.com/papertrail/remote_syslog2/releases/download/v0.15/remote_syslog_linux_amd64.tar.gz && \
tar xzf ./remote_syslog*.tar.gz && \
cd remote_syslog && \
cp ./remote_syslog /usr/local/bin && \
yum -y install postgresql && yum clean all
ADD customization/DigiCertCA.pem /etc/pki/ca-trust/source/anchors/DigiCertCA.pem
RUN update-ca-trust extract
# install nginx
RUN yum install nginx
# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/
# Set the default command to execute when creating a new container
CMD service nginx start
CMD ["find / -type f -exec ls -l {} \;"]
CMD ["chmod 666 customization/*.properties"]
ADD customization /opt/jboss/wildfly/customization/
COPY customization/WebService.* /opt/jboss/wildfly/standalone/deployments/
ADD newrelic /opt/jboss/wildfly/newrelic/
CMD ["/opt/jboss/wildfly/customization/execute.sh"]
EXPOSE 8080
Your problem is that you didn't add the nginx repository to your container.
Try adding this step before you run yum install nginx
RUN yum -y install epel-release
Two extra tips -
1. Install yum packages with the -y flag, otherwise they will fail for lack of user input.
2. Try to put all of your package install commands in one RUN command, to reduce layers in your image.
For example, I would Nginx to your current Dockerfile like so -
RUN yum -y install wget && \
wget https://github.com/papertrail/remote_syslog2/releases/download/v0.15/remote_syslog_linux_amd64.tar.gz && \
tar xzf ./remote_syslog*.tar.gz && \
cd remote_syslog && \
cp ./remote_syslog /usr/local/bin && \
yum -y install postgresql \
yum -y install epel-release && \
yum -y install nginx && yum clean all

Where my files exist in Docker image?

I'll switch to container based infrastructure in my Travis-CI builds. So
I wrote following commands in my Dockerfile, image was successfully built:
RUN apt-get install software-properties-common -y
RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y
RUN apt-get update
RUN apt-get install gcc-4.9 -y
RUN apt-get install build-essential perl python git -y
RUN apt-get install "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev libxrender-dev -y
RUN apt-get install libedit-dev -y
RUN apt-get install flex bison gperf libicu-dev libxslt-dev -y
RUN git clone git://code.qt.io/qt/qt5.git qt5
RUN cd qt5 && perl init-repository
RUN unset QTDIR
RUN export PATH="$PWD/qtbase/bin:$PWD/qtrepotools/bin:$PATH"
RUN cd qt5 && ./configure -developer-build -opensource -confirm-license -nomake examples -nomake tests
RUN cd qt5 && make
RUN cd qt5 && make install
RUN git clone git://code.qt.io/qt-creator/qt-creator.git qt-creator
RUN mkdir qt-creator-build
RUN cd qt-creator-build
RUN ../qt5/qtbase/bin/qmake -r ../qt-creator/qtcreator.pro
RUN make -j5
Before I push it to Docker Hub I need to know where is my stuff was created in the image. I need something like map of my files for getting access from Travis-CI. Please help me to understand. Thanks
UPD: actually, I need only an absolute path of qt-creator-build folder.
Based on your commands, the absolute path to the qt-creator-build folder should be /qt-creator-build, as the root directory / is the default working directory for every docker command.
That said, the command RUN make -j5 should probably be RUN cd qt-creator-build && make -j5, but only if you actually want to run make -j5 inside qt-creator-build, and that's what I understood from your code.
From the docs of Docker, you can use the WORKDIR command to change de working directory, like:
WORKDIR qt-creator-build

Resources