0

I'm trying to setup a CD/CI build environment with docker compose. I have a jenkins container, a sonar container and an archiva container. The problem is, my jenkins cannot connect to sonar and archiva.

I tried linking multiple containers together or joining them in the same network, but still no success.

In jenkins, I get the following error:

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8081 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

This is my docker-compose file.

version: '2'

volumes:
  data-jenkins:
    driver: 'local'
  data-postgres:
    driver: 'local'
  data-sonarqube-conf: 
    driver: 'local'
  data-sonarqube-data: 
    driver: 'local'
  data-archiva:
    driver: 'local'

services:
  jenkins:
    image: 'jenkins'
    ports:
      - '8080:8080'
    restart: 'always'
    volumes:
      - 'data-jenkins:/var/jenkins_home'
    links:
      - 'sonarqube:sonarqube'
  postgres:
    image: 'postgres:9.6.1'
    environment:
      - 'POSTGRES_USER=postgres'
      - 'POSTGRES_PASSWORD=postgres'
    ports:
      - '5432:5432'
    restart: 'always'
    volumes:
      - 'data-postgres:/var/lib/postgresql/data'
  sonarqube:
    image: 'sonarqube'
    depends_on:
      - 'postgres'
    ports:
      - '9000:9000'
    links:
      - 'postgres:postgres'
    environment:
      - 'SONARQUBE_JDBC_URL=jdbc:postgresql://postgres:5432/'
      - 'SONARQUBE_JDBC_USERNAME=postgres'
      - 'SONARQUBE_JDBC_PASSWORD=postgres'
    volumes:
      - 'data-sonarqube-data:/var/lib/sonarqube/data'
      - 'data-sonarqube-conf:/var/lib/sonarqube/conf'
  archiva:
    image: 'xetusoss/archiva'
    ports:
      - '8081:8080'
    volumes:
      - 'data-archiva:/var/archiva'
    environment:
      - 'SSL_ENABLED=false'

It seems the Jenkins container is living in a seperate environment. Does anyone how can i join all the environments together? Been struggling with this problem for almost a week now

Pascal W.
  • 3
  • 1
  • 6
  • yes, they are living in different environments, so to speak. to help you understand what is going on, get into the jenkins container (`docker exit -it [CONTAINER_ID] bash`) after you fire them all up, and then `ping archiva`. you were attempting connect to localhost, which won't work. it may or may not work to `ping archiva` (since you're not linking it to the jenkins container), but you can mess with it. it looks like you're currently linking to sonarqube, so i'd expect that ping to work. – burnettk Sep 02 '17 at 14:58

2 Answers2

2

To reference your sonarqube container from Jenkins use sonarqube:9000 docker will translate your service name sonarqube to the ip of that container.

I would also recommend using different networks rather than links to connect your containers.

ssc327
  • 690
  • 1
  • 9
  • 19
  • No problem. Please accept the answer so other users can reference it too. – ssc327 Sep 02 '17 at 16:30
  • @ssc327 Why is it better to use different networks rather than links? I would love more detail on this – Pasha Skender Jul 22 '18 at 22:16
  • 1
    @Loren I believe that links are deprecated. Have a look at https://stackoverflow.com/questions/41294305/docker-compose-difference-between-network-and-link – ssc327 Jul 22 '18 at 22:18
0

This is because the ping is going to sonarqube.

abhishek Sharma
  • 140
  • 2
  • 14