shiny docker image build failed due to ubuntu package issue - r

I'm trying to build docker image for my R shiny app. Below is theDockerfile.
# Install R version 3.6
FROM r-base:3.6.0
# Install Ubuntu packages
RUN apt-get update && apt-get install -y \
sudo \
gdebi-core \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
xtail \
wget \
libudunits2-dev \
libgdal-dev
# Install R packages that are required
RUN R -e "install.packages(c('remotes', 'tidyr', 'dplyr', 'ggplot2', 'stringr','shiny', 'shinydashboard','shinyWidgets','shinyjs', 'rlang','scales','DT','lubridate', 'plotly', 'leaflet', 'leafpop', 'visNetwork', 'wordcloud2', 'arules'), repos='http://cran.rstudio.com/')"
RUN R -e "remotes::install_github('nik01010/dashboardthemes')"
# Download and install ShinyServer (latest version)
RUN wget --no-verbose https://download3.rstudio.org/ubuntu-14.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt) && \
wget --no-verbose "https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
gdebi -n ss-latest.deb && \
rm -f version.txt ss-latest.deb
# Copy configuration files into the Docker image
COPY shiny-server.conf /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/
# Make the ShinyApp available at port 80
EXPOSE 80
# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh
CMD ["/usr/bin/shiny-server.sh"]
However, my image building failed quite early. Below is all the logs. It seems like some Ubuntu package issue which I do not quite understand.
I'm new to docker. I have not clue what to do with those error messages. Appreciate if anyone can help find out what needs to be done. Thanks.
Sending build context to Docker daemon 113.4MB
Step 1/10 : FROM r-base:3.6.0
---> 876f4d7b60e9
Step 2/10 : RUN apt-get update && apt-get install -y sudo gdebi-core pandoc pandoc-citeproc libcurl4-gnutls-dev libcairo2-dev libxt-dev xtail wget libudunits2-dev libgdal-dev
---> Running in 825a69c5a05f
Get:2 http://deb.debian.org/debian testing InRelease [116 kB]
Get:1 http://cdn-fastly.deb.debian.org/debian sid InRelease [146 kB]
Get:3 http://deb.debian.org/debian testing/main amd64 Packages [7,690 kB]
Get:4 http://cdn-fastly.deb.debian.org/debian sid/main amd64 Packages [8,225 kB]
Fetched 16.2 MB in 6s (2,724 kB/s)
Reading package lists...
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:
libc6-dev : Breaks: libgcc-8-dev (< 8.4.0-2~) but 8.3.0-7 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
The command '/bin/sh -c apt-get update && apt-get install -y sudo gdebi-core pandoc pandoc-citeproc libcurl4-gnutls-dev libcairo2-dev libxt-dev xtail wget libudunits2-dev libgdal-dev' returned a non-zero code: 100

The error message you are receiving is not Docker specific, but rather concerns your package manager apt.
Although you are updating the package list using apt-get update, you do not install newer versions of packages. What happens now is that you are trying to install a newer version of an already installed package which leads to the error message.
If you use apt-get upgrade, apt will install the newer versions of your installed packages.
Changing the 5th line as shown below will fix that issue:
RUN apt-get update && apt-get upgrade -y && apt-get install -y \

Related

Copying R Libraries to Docker Image from Local Libraries

I created a renv for my Shiny app. As you know that when you build a dockerfile, it has to install every package and its dependencies. If there are many packages, it takes long time.
I already installed packages my local machine. Also, the app will run on the remote machine. Is there any chance to copy the all libraries without restoring the renv? My local machine is macOS and my remote machine is Ubuntu. Due to the different Operating Systems might not work to use libraries. Probably, there are different dependencies between macOS and Ubuntu for the R packages.
Which is the best way to install R packages in a Dockerfile? Should I wait long docker building every time?
Directory
FROM openanalytics/r-base
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
nano \
automake \
pandoc \
pandoc-citeproc \
libcurl4-openssl-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
libssl1.1 \
libmpfr-dev \
# RPostgres
libpq-dev \
libssl-dev \
# rvest
libxml2-dev \
libssl-dev
# Install Packages
# RUN R -e "install.packages(c('janitor','DBI','RPostgres','httr', 'rvest','xml2', 'shiny', 'rmarkdown', 'tidyverse', 'lubridate','shinyWidgets', 'shinyjs', 'shinycssloaders', 'openxlsx', 'DT'), repos='https://cloud.r-project.org/')"
# copy the app to the image
RUN mkdir /root/appfile
COPY appfile /root/appfile
# renv restore
RUN Rscript -e 'install.packages("renv")'
RUN Rscript -e "renv::restore(lockfile = '/root/appfile/renv.lock')"
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/root/appfile')"]
Thanks.

How to install python3.6 on Ubuntu 22.04

I need to install this specific python version, to prepare a developer environment, because I'm maintaining a system with multiple libraries based on python 3.6.9.
I recently installed Ubuntu 22.04 on my laptop, but I had no success trying to install this python version.
I tried to install with apt-get after adding the deadsneak repository, but this python version is not available.
I tried installing from source by compiling, but it did not work. Running sudo make altinstall exited with this error:
Segmentation fault (core dumped)
make: *** [Makefile:1112: altinstall] Erro 139
I have faced the same problems and could make it work by adding some additional flags when running ./configure
Here are my steps:
Step 1 – Prerequsities
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev \
libgdbm-dev libnss3-dev libedit-dev libc6-dev
Step 2 – Download Python 3.6
wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz
tar -xzf Python-3.6.15.tgz
Step 3 – Compile Python Source
cd Python-3.6.15
./configure --enable-optimizations -with-lto --with-pydebug
make -j 8 # adjust for number of your CPU cores
sudo make altinstall
Step 4 – Check the Python Version
python3.6 -V
If you need it to install with pyenv, you could try this one:
$ sudo apt install clang -y
$ CC=clang pyenv install 3.6.9

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.

error: --with-readline=yes (default) and headers/libs are not available

I am installing R. I am getting this error when runing ./configure :
checking for history_truncate_file... no
configure: error: --with-readline=yes (default) and headers/libs are not available
Any hint,
Thanks
Use the following command will solve this problem
./configure --with-readline=no --with-x=no
--with-x=no turns off the X Windows System . It is the GUI for the Linux and Unix-like OS. My computer has no X Windows installed, so I turn off.
But I highly recommand to install readline library before R installtion with '--with-readline=yes', as the command operation style is quitely unfriendly with '--with-readline=no' . See more libreadline installation in linux for more details
you can use the following command for more install configuration details
./configure --help
on I found problem on compiling R 3.1.1 so as a part of solution , i recommend to install the below libraries first before you compile this R and use
sudo apt-get install build-essential
sudo apt-get install fort77
sudo apt-get install xorg-dev
sudo apt-get install liblzma-dev libblas-dev gfortran
sudo apt-get install gcc-multilib
sudo apt-get install gobjc++
sudo apt-get install aptitude
sudo aptitude install libreadline-dev
Thank you other people who posted and kept the knowledge going..
I think you need the GNU readline package. You can install it with apt-get, aptitude, or the appropiate tool for your distribution. In Ubuntu:
aptitude install libreadline-dev
On Linux version 2.6.18-371.3.1.el5 (centos) the following worked for me
yum install readline-devel
and use --with-x=no in configure option as mentioned by others
I added this in the file taken here:
http://www.personal.psu.edu/mar36/blogs/the_ubuntu_r_blog/2012/08/installing-the-development-version-of-r-on-ubuntu-alongside-the-current-version-of-r.html
CXXFLAGS="-ggdb -pipe -Wall -pedantic -I/usr/include/readline5" \
CPPFLAGS="-I/usr/include/readline5" \
LDFLAGS="-L/usr/lib64/readline5" \
On Centos 7, building R-3.5.0, If you want to install in /data/R-3.0.5.
wget https://www.stats.bris.ac.uk/R/src/base/R-3/R-3.5.0.tar.gz
tar -zxvf R-3.5.0.tar.gz
cd R-3.5.0.tar.gz
mkdir -p /data/R-3.0.5
yum group install "Development tools" -y
yum install readline-devel -y
yum install xorg-x11-server-devel libX11-devel libXt-devel -y
yum yum install libbz2-devel -y
yum install lzma -y
yum install xz xz-devel -y
yum install pcre pcre-devel -y
yum install libcurl-devel -y
yum install texinfo -y
yum install texinfo-tex -y
yum install texlive -y
yum install texlive-fonts-extra -y
yum install levien-inconsolata-fonts -y
yum install java-1.8.0-openjdk -y
./configure --prefix=/data/R-3.0.5 '--with-cairo' \
'--with-jpeglib' '--with-readline' '--with-tcltk' \
'--with-blas' '--with-lapack' '--enable-R-profiling' \
'--enable-R-shlib' \
'--enable-memory-profiling'
make
make install
The error means your system cannot find the required package. On Ubuntu, you can refer to this document to install all missing dependencies. It works for R 4.0
https://github.com/Jiefei-Wang/Painless-R-compilation-and-installation-on-Ubuntu

Resources