Skip to main content

Configure Jenkins (Docker-Outside-Of-Docker)

Hi Folks,
Today I will teach you how to configure Jenkins docker container  inside Ubuntu16.04.

so lets dig into, happy learning
Q: what is Docker-Outside-Of-Docker?
Ans: This approach allows you to run any Docker container in your Jenkins build script. This image creates Docker sibling containers rather than children which would be created if Docker-In-Docker (dind) was used. Some advantages of dood over dind:
  • enables sharing of images with host OS
    • eliminates storing images multiple times
    • makes it possible for Jenkins to automate local image creation
  • eliminate the need for supervisord (which means multiple processes)
  • eliminates a virtualization layer (lxc)
  • allows greater flexibility at runtime
  • permits the jenkins (sudo)user to run docker without the sudo prefix


  1.  Access your Ubuntu via ssh or open desktop version (if you are using locally)

Install Docker Damon,

Execute below commands  

    1. Update the apt package index
      sudo apt-get update
    2. Install packages to allow apt to use a repository over HTTPS:
      sudo apt-get install \
          apt-transport-https \
          ca-certificates \
          curl \
          software-properties-common
    3. Add Docker’s official GPG key:
      curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    4. Use the following command to set up the stable repository. (for x86_64)
      sudo add-apt-repository \
         "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
         $(lsb_release -cs) \
         stable"
    5. Update the apt package index.
      sudo apt-get update
    6. Install the latest version of Docker CE
      sudo apt-get install docker-ce
    7. Reference

Install Jenkins

Execute below commands  

  1. asdasdasd
    sudo su -
  2. Create folder with name jenkins:
    mkdir jenkins
    cd jenkins
  3. Create file with name Dockerfile (assume you have already installed vim)
    vi Dockerfile
  4. Paste below in the newly craeted Dockerfile
    FROM jenkins:latest
    USER root
    RUN apt-get update \
          && apt-get install -y sudo \
          && rm -rf /var/lib/apt/lists/*
    RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
    USER jenkins
    
  5. Create image from above file created
    docker build -t myjenk .
    
  6. Create named data volume container which will be mapped on Jenkins, so in future you want to update Jenkins version your data will not be lost
    docker create -v /var/jenkins_home --name jenkins-latest myjenkins 
    
  7. Run docker volume from
    docker run -d -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) -v /var/jenkins_home/workspace:/var/jenkins_home/workspace  -p 80:8080 --volumes-from jenkins-latest --name myjenkins myjenk
    
    $(which docker):$(which docker): This will mapp your host machine docker on Jenkins docker location. so your Jenkins will be able to user host docker binaries and create dockers on host (not inside jenkins).
    /var/jenkins_home/workspace:/var/jenkins_home/workspace: This will mapped all jobs folder on host machine, so when you copy file when creating new docker then it will be available to docker command. 
  8. Go inside Jenkins docker container
    docker exec -d myjenkins touch /bin/bash

  9. docker exec -it myjenkins  bash
  10. Update the apt package index.
    sudo apt-get update
  11. Run below commands as well so that you can get docker local setting
    sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common
    Install recommended plugins and set admin user.
    Enjoy your Jenkins is ready and running on port 80

Comments

Popular posts from this blog

Token replacement in Jenkins

Hi Folks, Today we are configuring our Jenkins to replace tokens in code before deployment. Please follow below steps. Create Project in git ( github  or any other git providing tool) Create a project which will contains all token values. in my case here is  public demo project . Deploy it in Jenkins as freestyle project , select git in Source Code Management and paste your git repository URL. If it is public then you don't need credentials to enter otherwise you have to. Build your project and check console output. Copy directory structure ( ref: below console snapshot). This is the physical directory structure of our deployed code in Jenkins hosted docker/OS. Configure project (in which token need to be changed) Create build.xml in your project root and past below code <project name="demo-app-tokenparser" default="useregex" basedir="."> <target name="useregex"> <property file="/var/jenkins_home/works

Deploy php Application into docker using Jenkins

Hi Folks, In my previouspost we have configured Jenkins docker with Docker-Outside-Of-Docker approach. Today we will be creating docker from php application and deploying through Jenkins as sibling to Jenkins docker. Below are the detail steps Configure PHP code I will be using yii2 application which will help those who want to deploy other php framework applications. ·          Create a file with name: Dockerfile on your project root. Paste below contents in the file created FROM webdevops/php-apache-dev COPY . /app RUN apt-get update COPY ./config/vhost.conf /opt/docker/etc/httpd/vhost.conf COPY ./config/10-server.conf /opt/docker/etc/httpd/conf.d RUN chmod 777 /app/runtime RUN chmod 777 /app/web/assets             ·          Create a folder with name : config on your project root. ·          Create a file with name: vhost.conf inside config folder. Paste below contents in the file created ####################################### # Vhost ##