Not deploy sonarqube and Docker Swarm

Hello,
I’m having trouble deploying sonarqube, postgresql deploys normally, but sonarqube is READY, and with that I can’t see in the log what is happening.
Someone could have an idea of what’s going on.

  • Docker 19.03.11
  • Docker Swarm (Cluster)
  • Traefik v2.2
  • Sonarqube latest
  • Postgres latest

[root@master-node01 ~]# cat sonarqube.yml
version: “3.2”

services:
sonarqube:
image: sonarqube
environment:
- SONARQUBE_HOME=/opt/sonarqube
- SONARQUBE_JDBC_USERNAME=sonar
- SONARQUBE_JDBC_PASSWORD=sonar
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
volumes:
- /opt/data/sonarqube/conf:/opt/sonarqube/conf
- /opt/data/sonarqube/data:/opt/sonarqube/data
- /opt/data/sonarqube/extensions:/opt/sonarqube/extensions
- /opt/data/sonarqube/bundled_plugins:/opt/sonarqube/lib/bundled-plugins
ports:
- 9000:9000
- 9092:9092
networks:
- net
- traefik-public
deploy:
resources:
limits:
cpus: ‘0.50’
memory: 2048M
reservations:
cpus: ‘0.25’
memory: 512M
placement:
constraints:
- node.role == manager
labels:
- traefik.enable=true
- traefik.docker.network=traefik-public
- traefik.constraint-label=traefik-public
- traefik.http.routers.sonarqube-web-http.rule=Host(sonar.${DOMAIN?Variable not set})
- traefik.http.routers.sonarqube-web-http.entrypoints=http
- traefik.http.routers.sonarqube-web-http.middlewares=https-redirect
- traefik.http.routers.sonarqube-web-https.rule=Host(sonar.${DOMAIN?Variable not set})
- traefik.http.routers.sonarqube-web-https.entrypoints=https
- traefik.http.routers.sonarqube-web-https.tls=true
- traefik.http.routers.sonarqube-web-https.tls.certresolver=le
- traefik.http.services.sonarqube-web.loadbalancer.server.port=9000

db:
image: postgres
networks:
- net
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
volumes:
- /opt/data/postgresql_data:/var/lib/postgresql/data

networks:
net:
driver: overlay
attachable: true
traefik-public:
external: true

[root@master-node01 ~]# docker stack ps sonarqube
ID NAME IMAGE NODE DESIRED STATE
blmu5v5a1kc8 sonarqube_sonarqube.1 sonarqube:latest master-node01 Ready
y424457o59bs _ sonarqube_sonarqube.1 sonarqube:latest master-node01 Shutdown
9j921atsxkqe _ sonarqube_sonarqube.1 sonarqube:latest master-node01 Shutdown
mcjcfp3cgpa1 _ sonarqube_sonarqube.1 sonarqube:latest master-node01 Shutdown
uo9jdh4zfj7o _ sonarqube_sonarqube.1 sonarqube:latest master-node01 Shutdown
v5f9bcx01hpu sonarqube_db.1 postgres:latest master-node01 Running
k3b5ec67q7x3 _ sonarqube_db.1 postgres:latest node01 Shutdown
kx6jjpldi0ec _ sonarqube_db.1 postgres:latest node01 Shutdown
uzmvgqh3cgvs _ sonarqube_db.1 postgres:latest node01 Shutdown
rlydk931f2b3 _ sonarqube_db.1 postgres:latest node01 Shutdown

Hello @efcunha,

I ran the same config as a swarm stack as well and it worked fine. I removed the whole part related to the public network though:

version: "3.2"

services:
  swsq:
    image: sonarqube
    ports:
      - "9000:9000"
    networks:
      - swsqnet
    environment:
      - SONAR_JDBC_URL=jdbc:postgresql://swdbsq:5432/sonar
      - SONAR_JDBC_USERNAME=sonar
      - SONAR_JDBC_PASSWORD=sonar
    volumes:
      - swsq_data:/opt/sonarqube/data
      - swsq_extensions:/opt/sonarqube/extensions
      - swsq_logs:/opt/sonarqube/logs
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 2048M
        reservations:
          cpus: '0.25'
          memory: 512M
      placement:
        constraints:
          - node.role == manager

  swdbsq:
    image: postgres
    ports:
      - "5442:5432"
    networks:
      - swsqnet
    environment:
      - POSTGRES_USER=sonar
      - POSTGRES_PASSWORD=sonar
    volumes:
      - /sq/postgresql:/var/lib/postgresql
      - /sq/postgresqldata:/var/lib/postgresql/data

networks:
  swsqnet:
    external: true

volumes:
  swsq_data:
    external: true
  swsq_extensions:
    external: true
  swsq_logs:
    external: true

Then:

antoine@sq$ docker stack deploy --compose-file sq.yml sqstack
Creating service sqstack_swdbsq
Creating service sqstack_swsq

antoine@sq$ docker stack ps sqstack
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
s31r9wvjf4xt        sqstack_swsq.1      sonarqube:latest    docker-desktop      Running             Running 3 minutes ago
np5yrw91jr7e        sqstack_swdbsq.1    postgres:latest     docker-desktop      Running             Running 3 minutes ago

antoine@sq$ curl -IL http://localhost:9000
HTTP/1.1 200
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-cache, no-store, must-revalidate
vary: accept-encoding
Content-Type: text/html;charset=utf-8
Transfer-Encoding: chunked
Date: Tue, 23 Jun 2020 08:51:33 GMT 

I don’t see an issue in the config, so likely your issue is related to:

  • the public network that you setup (traefik-public). You can remove all that first to see if it works or not
  • your docker/swarm setup, but in that case it will be hard to help

AFAIK, the Ready state is swarm-related (ie. SQ was not even started inside the container), usually the docker stack ps has an error output to say where it failed, do you have anything that could help?

Generally speaking, it looks that your issue is more related to docker/swarm than SonarQube.

Antoine

Oh and just a side note, the reservations you setup are quite low. SQ has a total Java max heap set to: 512M (web process) + 512M (CE process) + 512 (Search process). Also, I think 1 cpu won’t be too much!

I’m not saying it won’t work, because it will, though performances will be pretty bad. But this is something you could test a monitor anyway.