skip to Main Content

I got two servers, 1 Linux AMI with Jenkins and other Linux AMI with Docker running on AWS.I want to configure my Jenkins server with my docker server. How I can achieve that? Basically I want both the instances to communicate and then I will be using my Jenkins instance to create a pipeline and build the docker images and push it to Dockerhub, for which I will be using my docker instance

2

Answers


  1. I think, sorry if I misunderstand, that you just want a Jenkins agent?
    Perhaps the documentation on setting up a Jenkins Agent will help you, and has all the necessary steps clearly laid out.

    Login or Signup to reply.
  2. One instance suffice for Jenkins installations(you must install Java and Docker on it beforehand). Here is example of my Docker inside Docker configuration,where we run containers on the host(read more in fantastic Bibin Wilson blog, docker-in-docker, to get clear picture of dind)

    Dockerfile

    FROM jenkins/jenkins
    
    USER root
    RUN apt-get -y update && 
        apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common && 
        curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && 
        add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" && 
        apt-get update && 
        apt-get -y install docker-ce docker-ce-cli containerd.io
    RUN curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && 
        chmod +x /usr/local/bin/docker-compose && 
        ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
        
    RUN usermod -u $HOST_UID jenkins
    RUN groupmod -g $HOST_GID docker
    RUN usermod -aG docker jenkins
    
    USER jenkins
    

    docker-compose file

    version: '3.1'
    services:
        jenkins:
            build:
                context: ./
                args:
                    HOST_UID: ${HOST_UID}
                    HOST_GID: ${HOST_GID}
            restart: unless-stopped
            environment:
              - "JAVA_OPTS=-Xmx3g -Xms2G"
            volumes:
                - ${HOST_DOCKER}:/var/run/docker.sock
                - ${HOST_JENKINS_DATA}:/var/jenkins_home
            ports:
                - "${HOST_WWW}:8080"
                - "${HOST_OTHER}:50000"
    

    .env variables file

    HOST_WWW=8180
    HOST_OTHER=8181
    HOST_DOCKER=/var/run/docker.sock
    HOST_JENKINS_DATA=/home/mikisamal/jenkins_home
    HOST_UID=1001
    HOST_GID=999
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search