In this page, we will practice CI / CD using "katacoda" (https://www.katacoda.com/), a "web service that allows you to launch a study instance for free from a browser". The content follows the link above, so if you have any questions, please go there.
Here, we introduce an example of using jenkins, which is the core of CI / CD. Check ** Overview ** for a quick look at what you'll learn in this scenario ** If you have any mistakes in understanding, please point it out **
-To build a container with jenkins, follow the steps below
Launch Jenkins First, execute the following command to execute jenkins as a docker container
docker run -d -u root --name jenkins \ //Background execution, root user, container name"jenkins"
-p 8080:8080 -p 50000:50000 \ //Port 8080 is for web dashboard, port 50000 is for communication with jenkins agent
-v /root/jenkins_2112:/var/jenkins_home \ //Mount path on the host side and path on the container side
jenkins/jenkins:2.112-alpine
This time there is another host terminal If you want to access, ssh connection
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6048602eb5b9 jenkins/jenkins:2.112-alpine "/sbin/tini -- /usr/…" 2 minutes ago Up2 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp jenkins
After confirming that the container has been successfully history, move from this link (default)
To log in, `` admin```,
`344827fbdbfb40d5aac067c7a07b9230```
The environment is like this
Configure Docker Plugin Here, set the Docker plugin By setting the Docker plugin, jenkins can communicate with the docker daemon via agent (see the schematic diagram below).
Click as follows on the dashboard Manage Jenkins> Manage Plugins> available tab Docker> Install without Restart
This plugin is treated as a cloud provider The container (jenkins agent) starts only when communicating with the docker host
Add Docker Agent Here, set the configuration to "start the container" in the agent prepared earlier.
Click as follows on the dashboard
Enter `tcp: //172.17.0.67: 2345``` (docker server) in "Docker"> Docker Host URI from Manage Jenkins> Configure System> Add a new cloud Successful communication with Docker daemon with this procedure If you want to check, compare the result of
Test Connection
of Docker Host URI with the result of typing
docker version
`` on the console.
$ docker version
Client:
Version: 18.05.0-ce
API version: 1.37
Go version: go1.9.5
Git commit: f150324
Built: Wed May 9 22:16:25 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.10
Git commit: 0520e24302
Built: Fri Mar 23 01:48:12 2018
OS/Arch: linux/amd64
Experimental: false
Next, set the agent container
benhall / dind-jenkins-agent: v2
/ var / run / docker.sock: /var/run/docker.sock
Connect with SSH
Create Build Project Here, set the container to be executed using the "jenkins-agent" mentioned earlier. The procedure is as follows
`Execute Shell``` from
`` Add Build Step```, describe the details of build as follows, and Savels
docker info
docker build -t katacoda/jenkins-demo:${BUILD_NUMBER} .
docker tag katacoda/jenkins-demo:${BUILD_NUMBER} katacoda/jenkins-demo:latest
docker images
Build Project
Here, actually execute the container build by jenkins from the dashboard
build now
Click
The jenkins-agent container is started from the jenkins container, and it takes some time because the container is started from there based on the dockerfile of Git. Occasionally, the dashboard shows the error
pending—Jenkins does n’t have label docker-agent
.
View Console Output After confirming the start of the container from jenkins, run the container on the console
$ docker run -d -p 80:80 katacoda/jenkins-demo:latest
~~~
$ curl host01
<h1>This request was processed by host: </h1>
docke image
Check the container image with
benhall/dind-jenkins-agent
Is docker-agent image
katacoda/jenkins-demo
Shows the creation of a container with jenkins
Also, focusing on the `TAG``` part,
1,2, latest``` are prepared. This means that in step 5 of "Create Build Project", ``
$ {BUILD_NUMBER}` `` was managed as a tag, and the container build process by jenkins was performed twice.
Recommended Posts