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:
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
- Access your Ubuntu via ssh or open desktop version (if you are using locally)
Install Docker Damon,
Execute below commands
- Update the apt package index
sudo apt-get update
- Install packages to allow apt to use a repository over HTTPS:
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
- Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- 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"
- Update the apt package index.
sudo apt-get update
- Install the latest version of Docker CE
sudo apt-get install docker-ce
Reference
Install Jenkins
Execute below commands
- asdasdasd
sudo su -
- Create folder with name jenkins:
mkdir jenkins cd jenkins
- Create file with name Dockerfile (assume you have already installed vim)
vi Dockerfile
- 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
- Create
image from above file created
docker build -t myjenk .
- 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
- Run
docker volume from
$(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).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
/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. - Go inside Jenkins docker container
docker exec -d myjenkins touch /bin/bash
docker exec -it myjenkins bash
- Update the apt package index.
sudo apt-get update
- 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
Post a Comment