banner
uyoung

uyoung

twitter

Deploying Jenkins with Docker

title: Deploying Jenkins with Docker
date: 2021-08-05 13:00:00
categories: Study Guide#

jenkins-ci_512

Installing Docker#

Please refer to the official Docker website for installation instructions for different systems. For this demonstration, I will be using CentOS.

Official Docker Installation Guide

Uninstalling old versions#

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Installation Method#

There are several installation methods available from the official website. For this installation, I will be using the simplest version.

Setting up the repository#

Install the yum-utils package (provides the yum-config-manager utility) and set up the stable repository.

 $ sudo yum install -y yum-utils
 
 $ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

Installing Docker Engine#

  1. Install the latest version of Docker Engine and containerd.
$ sudo yum install docker-ce docker-ce-cli containerd.io
  1. Start Docker.
$ sudo systemctl start docker
  1. Verify if Docker Engine is installed correctly by running the hello-world image.
$ sudo docker run hello-world

Installing Jenkins using a Docker image#

Pulling the image#

If the image pulling speed is slow, you can change the mirror source. I won't go into detail about the installation method here, please search for it yourself.

$ docker pull jenkinsci/blueocean

After the pulling is complete, you can use docker images to view the image.

$ docker images

REPOSITORY                      TAG           IMAGE ID       CREATED       SIZE
jenkinsci/blueocean           latest        4428e9c342c6   2 weeks ago   699MB

Using the jenkinsci/blueocean image#

$ docker run \
  -d \
  -u root \
  -p 8080:8080 \
  -v /root/jenkins-data:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$HOME":/home \
  jenkinsci/blueocean
  • -d: Run the container in the background and return the container ID.
  • -u: Execute as the root user.
  • -p: Specify port mapping in the format: host port:container port.
  • -v: Mount paths.

Here, -v /var/run/docker.sock:/var/run/docker.sock allows operating the host Docker from within the Jenkins container.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.