似乎由于法律原因,Java无法在docker镜像中单独安装,而是我们必须使用java镜像。
我正在使用java图像,根据需要安装了R,但是当我安装R软件包时出现错误
以下是我的Dockerfile:
FROM buildpack-deps:jessie-scm
# A few problems with compiling Java from source:
# 1. Oracle. Licensing prevents us from redistributing the official JDK.
# 2. Compiling OpenJDK also requires the JDK to be installed, and it gets
# really hairy.
RUN apt-get update && apt-get install -y --no-install-recommends \
bzip2 \
unzip \
xz-utils \
&& rm -rf /var/lib/apt/lists/*
# Default to UTF-8 file.encoding
ENV LANG C.UTF-8
# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
RUN { \
echo '#!/bin/sh'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
ENV JAVA_VERSION 7u111
ENV JAVA_DEBIAN_VERSION 7u111-2.6.7-2~deb8u1
RUN set -x \
&& apt-get update \
&& apt-get install -y \
openjdk-7-jdk="$JAVA_DEBIAN_VERSION" \
&& rm -rf /var/lib/apt/lists/* \
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
# If you're reading this and have any feedback on how this image could be
# improved, please open an issue or a pull request so we can discuss it!
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
libssl1.0.0
# system library dependency for the euler app
RUN apt-get update && apt-get install -y \
libmpfr-dev
RUN sudo apt-get install -y \
r-base r-base-dev
# basic shiny functionality
RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cloud.r-project.org/')"
# install dependencies
RUN R -e "install.packages('Rmpfr', repos='https://cloud.r-project.org/')"
# Special Package
RUN R -e "install.packages('shiny')"
RUN R -e "install.packages('shinydashboard')"
RUN R -e "install.packages('plyr')"
RUN R -e "install.packages('dplyr')"
RUN R -e "install.packages('ggplot2')"
RUN R -e "install.packages('tm')"
RUN R -e "install.packages('SnowballC')"
RUN R -e "install.packages('wordcloud')"
RUN R -e "install.packages('RWeka')"
RUN R -e "install.packages('reshape2')"
RUN R -e "install.packages('igraph')"
# copy the app to the image
RUN mkdir /root/testapp1
COPY testapp1 /root/testapp1
COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838
CMD ["R", "-e shiny::runApp('/root/testapp1')"]
当我尝试安装任何R包时,我会收到以下错误:
> install.packages('shiny')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Error in contrib.url(repos, type) :
trying to use CRAN without setting a mirror
Calls: install.packages -> grep -> contrib.url
Execution halted
The command '/bin/sh -c R -e "install.packages('shiny')"' returned a non-zero code: 1
如何解决这个问题的头痛。
感谢。
答案 0 :(得分:4)
在R环境中执行install.packages('shiny')
时,它会挂起,要求您从要下载的镜像中进行选择。
> install.packages('shiny')
Installing package into ‘/Users/user/Library/R/3.3/library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
HTTPS CRAN mirror
1: 0-Cloud [https]
2: Algeria [https]
...
55: (HTTP mirrors)
Selection:
根据你的错误输出似乎是命令
RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cloud.r-project.org/')"
并执行下一个,然后在尝试执行时失败(错误退出1):
RUN R -e "install.packages('shiny')"
提供install.packages('shiny', repos='https://cloud.r-project.org/')
代替sql_query = SELECT * FROM id, title, \
CAST(REPLACE('-','',good_code) AS unsigned) AS good_code \
FROM ...
可能会进行无提示安装而无需提出任何问题。
答案 1 :(得分:2)
看起来你得到的错误来自install.pacakges
方法,这些方法没有指定repos参数。
在我的本地计算机上使用您的dockerfile更新install.packages
repos='http://cran.us.r-project.org/'
后,图片构建成功。