複数コンテナ実行(Compose)
Jenkinsコンテナ実行
記述例:docker-compose.yml
version:"3" services: master: container_name: master image: jenkins:latest ports: - 8080:8080 volumes: - ./jenkins_home:/var/jenkins_home
※volumes=ホスト側:カレントディレクトリ直下のjenkins_home/コンテナ側:/var/jenkins_home
$ pwd /home/docker/sample $ ls -la 合計 12 drwxrwxr-x. 2 docker docker 4096 11月 6 20:18 . drwx------. 6 docker docker 4096 11月 6 20:18 .. -rw-rw-r--. 1 docker docker 166 11月 6 20:18 docker-compose.yml $ pwd /home/docker/sample $ ls docker-compose.yml $ docker-compose up Creating network "sample_default" with the default driver Pulling master (jenkins:latest)... latest: Pulling from library/jenkins 55cbf04beb70: Pull complete 1607093a898c: Pull complete 9a8ea045c926: Pull complete d4eee24d4dac: Pull complete c58988e753d7: Pull complete 794a04897db9: Pull complete 70fcfa476f73: Pull complete 0539c80a02be: Pull complete 54fefc6dcf80: Pull complete 911bc90e47a8: Pull complete 38430d93efed: Pull complete 7e46ccda148a: Pull complete c0cbcb5ac747: Pull complete 35ade7a86a8e: Pull complete aa433a6a56b1: Pull complete 841c1dd38d62: Pull complete b865dcb08714: Pull complete 5a3779030005: Pull complete 12b47c68955c: Pull complete 1322ea3e7bfd: Pull complete Creating master ... done Attaching to master master | Running from: /usr/share/jenkins/jenkins.war master | webroot: EnvVars.masterEnvVars.get("JENKINS_HOME") ~中略~ master | INFO: master | master | ************************************************************* master | ************************************************************* master | ************************************************************* master | master | Jenkins initial setup is required. An admin user has been created and a password generated. master | Please use the following password to proceed to installation: master | master | 911abe0f181f4b0c9cd3752c803fd615 master | master | This may also be found at: /var/jenkins_home/secrets/initialAdminPassword master | master | ************************************************************* master | ************************************************************* master | ************************************************************* master | master | --> setting agent port for jnlp master | --> setting agent port for jnlp... done master | Nov 06, 2018 11:41:05 AM hudson.model.UpdateSite updateData master | INFO: Obtained the latest update center data file for UpdateSource default master | Nov 06, 2018 11:41:05 AM hudson.model.UpdateSite updateData master | INFO: Obtained the latest update center data file for UpdateSource default master | Nov 06, 2018 11:41:05 AM hudson.WebAppMain$3 run master | INFO: Jenkins is fully up and running master | Nov 06, 2018 11:41:06 AM hudson.model.DownloadService$Downloadable load master | INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller master | Nov 06, 2018 11:41:08 AM hudson.model.DownloadService$Downloadable load master | INFO: Obtained the updated data file for hudson.tools.JDKInstaller master | Nov 06, 2018 11:41:08 AM hudson.model.AsyncPeriodicWork$1 run master | INFO: Finished Download metadata. 29,802 ms
ブラウザアクセス(http://localhost:8080)
ログイン
初期パスワード入力
※初期パスワードは、以下で確認可能
コンテナ側:/var/jenkins_home/secrets/initialAdminPassword
ホスト側:./jenkins_home/secrets/initialAdminPassword
Install suggested plugin押下
ユーザー作成
ホーム画面表示
Master JenkinsのSSHキー作成
$ docker container exec -it master ssh-keygen -t rsa -C "" Generating public/private rsa key pair. Enter file in which to save the key (/var/jenkins_home/.ssh/id_rsa): Created directory '/var/jenkins_home/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /var/jenkins_home/.ssh/id_rsa. Your public key has been saved in /var/jenkins_home/.ssh/id_rsa.pub. The key fingerprint is: SHA256:rSeBWHqwemaHOWtbzncuBDmEq5U3TPVU5B6EOl49Gd0 The key's randomart image is: +---[RSA 2048]----+ | . .. .++. . | | . o o.o. . E| | .*.. ...oo | | +*B.o...+. | | o+.o=So. .. | | .. + oo | | . B o.o . | | +.B oo. | | .o.o. +. | +----[SHA256]-----+
Jenkins Slaveコンテナ作成
記述例:docker-compose.yml
version: "3" services: master: container_name: master image: jenkins:latest ports: - 8080:8080 volumes: - ./jenkins_home:/var/jenkins_home links: - slave01 slave01: container_name: slave01 image: jenkinsci/ssh-slave environment: - JENKINS_SLAVE_SSH_PUBKEY=ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVnrSDJ0q0BoyMNiCLr8B9DrAd7qj6A2NYxRPkvWiCXUHY+ux/yJDXQogFQnycs+sXHjDQsJNWMkLtl7suH9EE9f04Jg80uhLbbBTpH7fNp90wqunmYmag6DmtrlKoBEYL2cgTPF2oXDECqrQHDz05TnAAf+gqAZ1EXD9vAYEzIeirsYwtMmwB76NrYHVDBWAQ4zRalOR2kMAhGETeDkdgVJcJPLlU74NEFVSSXqcZXGYFMiyzNzXKuUkpapQ2Rn5n7stjm6pDk+bgMkfF63ap8r/riiC5tcy7+BAHETvhSB2Z+CkXR7+/LbZibcEfRqn7R/zv+iyZqOdHoGE1Qa9D
JENKINS_SLAVE_SSH_PUBKEY環境変数には、./jenkins_home/.ssh/id_rsa.pubの内容をコピペ
master/slave01実行
$ docker-compose up -d $ docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------ master /bin/tini -- /usr/local/bi ... Up 50000/tcp, 0.0.0.0:8080->8080/tcp slave01 setup-sshd Up 22/tcp
ノード追加
ホーム画面から、「Jenkinsの管理」→「ノード管理」→「新規ノード作成」
リモートFSルート:任意のディレクトリ(例:/home/jenkins)
起動方法:SSH経由でUnixマシンのスレーブエージェントを起動
ホスト:slave01
認証方法:(追加プルダウン)Jenkins
Host Key Verification Strategy:Non Verifying Verification Strategy