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

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

Related

Installing R in a docker container

I'm trying to install in a Ubuntu:20.04 based container miniconda and, using the conda keyword, R:4.05.
The Dockerfile I'm using is this:
FROM ubuntu:20.04
USER root
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get -y install libcurl4-openssl-dev
RUN apt-get install -y wget
RUN mkdir -p ~/miniconda3
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh
RUN bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
RUN export PATH=~/miniconda3/bin:$PATH
RUN rm -rf ~/miniconda3/miniconda.sh
RUN ~/miniconda3/bin/conda init bash
RUN ~/miniconda3/bin/conda init zsh
RUN ~/miniconda3/bin/conda config --add channels conda-forge
RUN ~/miniconda3/bin/activate
RUN ~/miniconda3/bin/conda install -y -c conda-forge r-base
RUN R -e "install.packages('BiocManager')"
RUN R -e "BiocManager::install('DESeq2')"
From lines 8 to 16 I download miniconda and run it in ~/miniconda3
In line 17:
RUN R -e "install.packages('BiocManager')"
I try to use R and install the BiocManager package from the command line, but I receive this error:
> [16/17] RUN R -e "install.packages('BiocManager')":
#19 2.767 /bin/sh: 1: R: not found
------
executor failed running [/bin/sh -c R -e "install.packages('BiocManager')"]: exit code: 127
I've also tried to start from the official distribution of Rocker, but in this way (the way I've shown you in this post) I would prefer it since I would end up with an image in which I have both miniconda and R.
Can someone help me?
Thanks a lot!
Each RUN command runs in a separate shell, so your export command sets the path, but then the shell exits and the path is reset for the next RUN command.
You also have to use the absolute path. Tilde expansion doesn't work.
Instead of
RUN export PATH=~/miniconda3/bin:$PATH
try
ENV PATH=/root/miniconda3/bin:$PATH

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 build Dockerfile with R & Java

I'm trying to build a Docker container that runs R with the package RJava. I have tried the following code:
# Install R version 3.6.3
FROM rocker/tidyverse:3.6.3
# Make ~/.R
RUN mkdir -p $HOME/.R
# Install Ubuntu packages && then R packages
RUN install2.r --error \
lubridate magrittr RPostgres DBI broom rlang rJava
However I get the following: installation of package ‘rJava’ had non-zero exit status.
Can anyone help me with this. I'm thinking that maybe it is because Java is not installed. Does anyone know how to install Java on this docker container?
I've tried adding the following to my dockerfile as per another post I found however I get the error saying 'The repository 'http://ppa.launchpad.net/webupd8team/java/ubuntu focal Release' does not have a Release file:
# Install "software-properties-common" (for the "add-apt-repository")
RUN apt-get update && apt-get install -y \
software-properties-common
# Add the "JAVA" ppa
RUN add-apt-repository -y \
ppa:webupd8team/java
# Install OpenJDK-8
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f;
# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
I'm new to docker and any help with this would be much appreciated.
The rocker images are based on debian, not ubuntu. Specifically it is Debian GNU/Linux 10 (buster). With that version, you can install java by installing the package openjdk-11-jdk via apt and you don't need to add any repositories for openjdk-8-jdk.
So a working dockerfile that installs rJava:
FROM rocker/tidyverse:3.6.3
RUN apt-get update && \
apt-get install -y openjdk-11-jdk && \
apt-get install -y liblzma-dev && \
apt-get install -y libbz2-dev
RUN Rscript -e "install.packages('rJava')"
Note: liblzma-dev and libbz2-dev are additional system dependencies for compiling rJava.

Docker NPM Install Not working

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"]

Docker - R creates multiple processes

I'm creating a docker container and I'm installing R in it.
The problem is, that when running R in the container, the main R process create ncores - 1 subprocesses.
So when running the docker on my laptop with 8 cores, I get 1 R process and 7 R subprocesses.
I also tried to configure my Docker file similar to this:
https://github.com/rocker-org/rocker/blob/eeb9c8a5f416f7cfe982734440e39fa72abbcb33/r-base/Dockerfile
but is still not working.
Docker-file:
FROM ubuntu:14.04
RUN sed -e 's/archive\.ubuntu/at\.archive\.ubuntu/g' -i /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y install libatlas3-base
RUN apt-get -y install libopenblas-base
RUN apt-get -y install r-base
RUN apt-get -y install r-base-dev
RUN apt-get -y install apt-utils
RUN echo "deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu/ trusty/" >> /etc/apt/sources.list
RUN gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
RUN gpg -a --export E084DAB9 | apt-key add -
RUN apt-get update
RUN apt-get -y --with-new-pkgs upgrade
Did someone encountered this problem?
I don't know why, but the whole problem was caused by installing libopenblas-base.
After removing the line
RUN apt-get -y install libopenblas-base
everything worked fine!

Resources