Skip to content

Instantly share code, notes, and snippets.

@kazusato
Last active December 9, 2023 06:45
Show Gist options
  • Save kazusato/98f7d60fbe0c8e720f97228d1c2a06d3 to your computer and use it in GitHub Desktop.
Save kazusato/98f7d60fbe0c8e720f97228d1c2a06d3 to your computer and use it in GitHub Desktop.
Run SonarQube with docker-compose

Problem

There is an instruction to run SonarQube with docker on the following URL (see the "Installing the Server from the Docker Image" section):

https://docs.sonarqube.org/latest/setup/install-server/

However, when I started a container with the following command, an Permission Denied error occurred.

$ docker run --name sqx -p 9000:9000 -v /tmp/workdir/data:/opt/sonarqube/data -v /tmp/workdir/extensions:/opt/sonarqube/extensions -v /tmp/workdir/logs:/opt/sonarqube/logs sonarqube:8.2-community

Cause

The SonarQube process runs as a user sonarqube (UID=999) within the container. However, if I create volumes (data, extensions, logs) with an owner of myself (UID != 999), the volume will be mounted with an owner of root within the container. Because the sonarqube user does not have a permission to write files to the root-owned directories, the process can't write files and, therefore, the Permission Denied error occurs.

Solution

If you mount volumes with an owner of UID=999 on the host, the volumes will be mounted as a sonarqube user owned directories within the container. Followings are the procedure to do so.

Create an user on host

Ubuntu is running on host.

$ sudo groupadd -g 999 dockervolume
$ sudo useradd -d /tmp -g dockervolume -s /usr/sbin/nologin -u 999 dockervolume

Create directories and change an owner

$ mkdir /tmp/workdir
$ mkdir /tmp/workdir/data
$ mkdir /tmp/workdir/extensions
$ mkdir /tmp/workdir/logs
$ sudo chown -R dockervolume:dockervolume /tmp/workdir

Run a SonarQube container

$ docker run --name sqx -p 9000:9000 -v /tmp/workdir/data:/opt/sonarqube/data -v /tmp/workdir/extensions:/opt/sonarqube/extensions -v /tmp/workdir/logs:/opt/sonarqube/logs sonarqube:8.2-community

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment