我正在尝试构建一个用于CI目的(Bitbucket Pipelines)的自定义Docker镜像。在构建并测试我的代码后,我希望能够使用SonarQube运行一些分析。
在我的自定义镜像中,我尝试安装Sonar-Scanner,这样在容器中只需执行即可。然而,在容器内部(无论是在Bitbucket还是在我的本地机器上),它都会失败,并显示以下错误:
在我的自定义镜像中,我尝试安装Sonar-Scanner,这样在容器中只需执行即可。然而,在容器内部(无论是在Bitbucket还是在我的本地机器上),它都会失败,并显示以下错误:
/sonar-scanner-2.8/bin/sonar-scanner: 108: exec: : Permission denied
我已经尝试了许多不同的方法来设置扫描器目录的权限和所有权,但是没有一种方法能够起作用。
更令人惊讶的是,即使使用 --privileged=true
来运行容器,我仍然得到相同的错误。
我在docker基础知识上缺少了什么?
这是我的最新Dockerfile版本:
# Pull base image.
FROM node:6
LABEL maintainer "Gabriel Araujo <contact@gbiel.com>"
ENV SONAR_SCANNER_VERSION 2.8
ENV SONAR_SCANNER_HOME /home/sonar-scanner-${SONAR_SCANNER_VERSION}
ENV SONAR_SCANNER_PACKAGE sonar-scanner-${SONAR_SCANNER_VERSION}.zip
ENV SONAR_RUNNER_HOME ${SONAR_SCANNER_HOME}
ENV PATH $PATH:${SONAR_SCANNER_HOME}/bin
ENV WORKDIR /home/workspace
# Define working directory.
WORKDIR ${WORKDIR}
# Install dependencies
RUN apt-get -yqq update && \
apt-get -yqq --no-install-recommends install git bzip2 curl unzip && \
npm install -g gulp bower && \
npm cache clean && \
apt-get -yqq autoremove && \
apt-get -yqq clean && \
rm -rf /var/lib/apt/lists/* /var/cache/* /tmp/* /var/tmp/*
# Allow root for bower
RUN echo '{ "allow_root": true }' > /root/.bowerrc
# Download sonar
RUN curl --insecure -OL https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/${SONAR_SCANNER_PACKAGE} && \
unzip ${SONAR_SCANNER_PACKAGE} -d /home && \
rm ${SONAR_SCANNER_PACKAGE}
RUN addgroup sonar && \
useradd -s /usr/sbin/nologin -d ${SONAR_SCANNER_HOME} -g sonar sonar && \
chown -R sonar:sonar ${SONAR_SCANNER_HOME} && \
chown -R sonar:sonar ${WORKDIR}
USER sonar