Skip to content

Instantly share code, notes, and snippets.

@dsample
Last active May 8, 2019 15:41
Show Gist options
  • Save dsample/79f1b7cd320132d1d166cb76e8676d28 to your computer and use it in GitHub Desktop.
Save dsample/79f1b7cd320132d1d166cb76e8676d28 to your computer and use it in GitHub Desktop.
Sonar Scanner as a Docker image

Sonar Scanner Docker Image

This shows how to build Sonar Scanner as a Docker image, so that you can run Sonar Scanner without having Java installed on the host.

The part where Node.JS is installed can be substituted with whatever is necessary to scan the target project.

Usage

  1. Build with docker build -t sonar:scanner .
  2. Run docker run --rm -it -v $(pwd):/src sonar:scanner, substituting the path to your project for the $(pwd) part if your source code isn't in the current directory.
FROM openjdk:latest
RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash - \
&& yum install -y curl unzip \
&& mkdir /sonar \
&& curl -sSL -o /scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492.zip \
&& unzip -qd /sonar/ /scanner.zip \
&& mv /sonar/*/* /sonar/ \
&& rm /scanner.zip \
&& yum erase -y unzip \
&& yum clean all \
&& useradd --user-group --create-home sonar
RUN yum install -y --enablerepo=nodesource nodejs
WORKDIR /src
USER sonar
CMD /sonar/bin/sonar-scanner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment