Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install R 3.4.4 in alpine

I am trying to install R in my alpine image of docker. Earlier I did install it in my ubuntu image using

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 \ && add-apt-repository 'deb [arch=amd64,i386] https://cran.rstudio.com/bin/linux/ubuntu xenial/' \ && apt-get update \ && apt-get install -y r-base

Nowhere I could find how to install it in alpine. Any help would be appreciated.

My base image is python:3.7-alpine

like image 391
Harshit Khetan Avatar asked May 15 '19 11:05

Harshit Khetan


People also ask

How do I install programs on Alpine?

Add a PackageUse add to install packages from a repository. Any necessary dependencies are also installed. If you have multiple repositories, the add command installs the newest package. If you only have the main repository enabled in your configuration, apk will not include packages from the other repositories.


1 Answers

R is available in Alpine community repositories, so it's just a matter of installing the proper package:

apk add R

For a more compact image you could start off a vanilla Alpine image, such as alpine:3.9, if you don't need Python specifically.

The latest R version available on Alpine is 3.5.1. The closest to 3.4.4 is 3.4.2, which is available in Alpine V3.7. In that case, start off Alpine V3.7:

$ docker run -it alpine:3.7 
/ # apk add R

If you need R version 3.4.4 exactly, you may have to build it from source. Fortunately, there is an excellent ready made Dockerfile by Artem Klevtsov which does just that:
https://github.com/artemklevtsov/r-alpine/blob/master/release/Dockerfile

Simply replace the R version string to 3.4.4 and build the image - works great.

Edit:

Another option for using a specific R version, which build is not available for native Alpine, is enabling glibc support on the Alpine container.

Normally, Alpine builds on musl libc, which is a specialized libc implementation that is generally not compatible to glibc, which is the de-facto standard libc used by most other Linux distributions. With glibc installed, you should be able to run any general-purpose R Linux build on the Alpine container.

The following Dockerfile portion would enable glibc support, adding some 10MB to the Alpine container size:

# Based on: https://github.com/anapsix/docker-alpine-java
FROM alpine:3.7

ENV GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc
ENV GLIBC_VERSION=2.28-r0

RUN set -ex && \
    apk --update add libstdc++ curl ca-certificates && \
    for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION}; \
        do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}/${pkg}.apk -o /tmp/${pkg}.apk; done && \
    apk add --allow-untrusted /tmp/*.apk && \
    rm -v /tmp/*.apk && \
    /usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib
like image 131
valiano Avatar answered Sep 28 '22 17:09

valiano