{"id":1604,"date":"2019-06-07T18:36:33","date_gmt":"2019-06-07T18:36:33","guid":{"rendered":"http:\/\/robermb.com\/blog\/?p=1604"},"modified":"2020-12-17T22:09:45","modified_gmt":"2020-12-17T21:09:45","slug":"how-to-install-jenkins-using-docker","status":"publish","type":"post","link":"https:\/\/robermb.com\/blog\/geeks\/how-to-install-jenkins-using-docker\/","title":{"rendered":"How to Install Jenkins using Docker"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><strong>Requirements:<\/strong><\/h3>\n\n\n\n<ul><li>Ubuntu Server Linux with <a href=\"https:\/\/docs.docker.com\/install\/linux\/docker-ce\/ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Docker installed (opens in a new tab)\">Docker installed<\/a>.<\/li><\/ul>\n\n\n\n<p><strong><em>Tip<\/em><\/strong>: I have installed a virtual machine using the image: &#8220;ubuntu-18.04.2-live-server-amd64&#8221;. <\/p>\n\n\n\n<p>You can download it from <a href=\"https:\/\/www.ubuntu.com\/download\/server\">https:\/\/www.ubuntu.com\/download\/server<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Jenkins Docker image<\/strong>:<\/h3>\n\n\n\n<p>Docker has a lot of images ready to use. For example, if you search on Google &#8220;docker jenkins image&#8221;:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"551\" height=\"262\" src=\"http:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-1.png\" alt=\"\" class=\"wp-image-1654\" srcset=\"https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-1.png 551w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-1-300x143.png 300w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-1-150x71.png 150w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><\/figure>\n\n\n\n<p>You will find the official Docker website to download Jenkins image:<\/p>\n\n\n\n<p><a href=\"https:\/\/hub.docker.com\/r\/jenkins\/jenkins\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">https:\/\/hub.docker.com\/r\/jenkins\/jenkins\/<\/a><\/p>\n\n\n\n<p>And you can see the instruction to deploy the image in your Docker environment (:lts for latest version):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker pull jenkins\/jenkins:lts<\/code><\/pre>\n\n\n\n<p>This is only an example to understand how Docker images work.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Deploy Jenkins Docker image<\/strong>:<\/h3>\n\n\n\n<p>These are the commands to deploy a Jenkins image and run it as a container:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Deploy Jenkins image\nrobermb@ubuntu:~$ sudo docker pull jenkins\/jenkins:lts\n\n# List current images\nrobermb@ubuntu:~$ sudo docker images\n\n# Run a container using Jenkins image.\n# Note: this will automatically create a 'jenkins_home' docker volume on the host machine, that will survive the container stop\/restart\/deletion.\nrobermb@ubuntu:~$ sudo docker run -d --name=jenkins_master -p 8080:8080 -p 50000:50000 -v jenkins_home:\/var\/jenkins_home jenkins\/jenkins:lts<\/code><\/pre>\n\n\n\n<p>To see if your container is running you can execute the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>robermb@ubuntu:~$ sudo docker ps<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Jenkins Web Access:<\/strong><br><\/h3>\n\n\n\n<p>URL to access Jenkins:  <a href=\"http:\/\/192.168.152.132:8080\">http:\/\/192.168.152.132:8080<\/a><\/p>\n\n\n\n<p><strong><em>Tip<\/em><\/strong>: The IP of my Ubuntu virtual machine is 192.168.152.132<br><\/p>\n\n\n\n<p>The first time you try to access to Jenkins web console, for security reasons you have to enter the password. That password was generated automatically during the installation.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/fJfDsjIMPk6XXSz-L66ORMmjfZBo0rl52xNu7HZuNisiLBPLLBhstZdjMWeIgYZWa_IWfM0pk4cPjlP92yoPWMvZ4ns7fxGFhf02o-wRGRBvDqoHVHRrhtlxKGldZq1wziae1xW1\" alt=\"\"\/><\/figure>\n\n\n\n<p>To get the default password of your Jenkins installation, just execute the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>robermb@ubuntu:~$ sudo docker exec Jenkins-Master cat \/var\/jenkins_home\/secrets\/initialAdminPassword\n\nPassword:\n4b79afe3f62a458c903a8da29fce80af<\/code><\/pre>\n\n\n\n<p>And you can see now the welcome screen:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"644\" src=\"http:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-3.png\" alt=\"\" class=\"wp-image-1666\" srcset=\"https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-3.png 1000w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-3-300x193.png 300w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-3-150x97.png 150w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>You can click now on <strong>Install suggested plugins<\/strong> to complete the installation or just click Select plugins to install manually.<\/p>\n\n\n\n<p>Create your admin user:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"519\" height=\"272\" src=\"http:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-5.png\" alt=\"\" class=\"wp-image-1669\" srcset=\"https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-5.png 519w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-5-300x157.png 300w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-5-150x79.png 150w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/figure>\n\n\n\n<p>Choose your Jenkins URL:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"772\" height=\"234\" src=\"http:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-6.png\" alt=\"\" class=\"wp-image-1670\" srcset=\"https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-6.png 772w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-6-300x91.png 300w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/image-6-150x45.png 150w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/figure>\n\n\n\n<p>And now <strong>Jenkins is ready!<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><em><strong>Tip<\/strong><\/em>:  to run docker commands directly with your user instead using &#8220;sudo docker&#8221; you can execute the following command to add your user to docker group:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>robermb@ubuntu:~$ sudo usermod -aG docker robermb\n\n# It's necessary to logout and login again with our user to apply the changes over the group:\nrobermb@ubuntu:~$ logout<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Update Jenkins (Docker)<\/h3>\n\n\n\n<p><strong><em>Note<\/em><\/strong>:  If you used an old or deprecated image version (e.g.: jenkins instead jenkins\/jenkins), or you just have an old version of Jenkins you will need to update your Jenkins installation manually, following these steps:<\/p>\n\n\n\n<p>These errors happened to me after the installation of an old image of Jenkins like version 2.60.3. To fix that is necessary to update Jenkins to 2.164.3 version.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/h2CuthGBdkaZ4S5IFNTo-J_ab_GBVZFTLdOhr3c8V0uDLLGsf72NY80uW70jnAMfRL-ChDTAem53yqG3P-m9wCz62O0jeJ02cjlvFla9VNc9IXiYYbEsNBM9QNRLBspbjVCTV0Il\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/dkQjVGMyCI6kY2_13htBjEub8HqCL2ZA07wD_7IfKcDnVjq-MtV19QOJQDRIPwHs_SIm3OGxyCkAw8039eXue2jm2jn6sCoUDOfu1Vm6BUxf8LgYRlNOCt5mLs2iN0poj1Y0gl_V\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Commands<\/h3>\n\n\n\n<p><strong>Message<\/strong>:   &#8220;New version of Jenkins (2.164.3) is available for <a rel=\"noreferrer noopener\" aria-label=\"download (opens in a new tab)\" href=\"http:\/\/updates.jenkins-ci.org\/download\/war\/2.164.3\/jenkins.war\" target=\"_blank\">download<\/a> (changelog)&#8221;<\/p>\n\n\n\n<ul><li>Right click on the download link and copy link address. (<a href=\"http:\/\/updates.jenkins-ci.org\/download\/war\/2.164.3\/jenkins.war\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">http:\/\/updates.jenkins-ci.org\/download\/war\/2.164.3\/jenkins.war<\/a>)<\/li><\/ul>\n\n\n\n<ul><li>Log in into jenkins container:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># using host's root with -u 0\nrobermb@ubuntu:~$ sudo docker container exec -u 0 -it Jenkins-Master bash<\/code><\/pre>\n\n\n\n<ul><li>Download the update file, using the link you copied before:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>root@81a46bda1d81:\/# wget http:\/\/updates.jenkins-ci.org\/download\/war\/2.164.3\/jenkins.war<\/code><\/pre>\n\n\n\n<ul><li>Move it to the correct place:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>root@81a46bda1d81:\/# mv .\/jenkins.war \/usr\/share\/jenkins<\/code><\/pre>\n\n\n\n<ul><li>Change file permission:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>root@81a46bda1d81:\/# chown jenkins:jenkins \/usr\/share\/jenkins\/jenkins.war<\/code><\/pre>\n\n\n\n<ul><li>Exit container (inside of your container):<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>root@81a46bda1d81:\/# exit<\/code><\/pre>\n\n\n\n<ul><li>Restart the container (from your Ubuntu server):<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>robermb@ubuntu:~$ sudo docker container restart Jenkins-Master<\/code><\/pre>\n\n\n\n<p>Now I&#8217;m only have some warnings but the errors have been fixed.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/zeVwRRrQa-OmRsVg-OtmMGyjYfDT3h6GxpIIP29AM5PD_-dP2mbYcbbAYzr2Xazw4s__O3EAdoxpQGFZmQn3aYZVy9KT0nb9AzpjZlncmj3oKz-aXle4q0MmTvWMiTqRr9m_yDJo\" alt=\"\"\/><\/figure>\n\n\n\n<p>To fix that:<\/p>\n\n\n\n<ul><li>Jenkins root url problem:<\/li><\/ul>\n\n\n\n<p>Go to <strong>Manage Jenkins<\/strong> -&gt; <strong>Configure System<\/strong> -&gt; <strong>Jenkins Location<\/strong> and complete the field &#8220;System Admin e-mail address&#8221; with your email.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"122\" src=\"http:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_location.png\" alt=\"\" class=\"wp-image-1641\" srcset=\"https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_location.png 533w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_location-300x69.png 300w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_location-150x34.png 150w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/figure>\n\n\n\n<ul><li>More Plugins problems:<\/li><\/ul>\n\n\n\n<p>Go to <strong>Manage Jenkins<\/strong> -&gt; <strong>Plugin Manager<\/strong> and click on Download now and install after reboot.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"623\" height=\"500\" src=\"http:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_update_plugins.png\" alt=\"\" class=\"wp-image-1642\" srcset=\"https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_update_plugins.png 623w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_update_plugins-300x241.png 300w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_update_plugins-150x120.png 150w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/figure>\n\n\n\n<ul><li>And now I only have a warning says &#8220;There are users who are still using a legacy API token&#8230;.&#8221;:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"991\" height=\"133\" src=\"http:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_warning_API_token.png\" alt=\"\" class=\"wp-image-1644\" srcset=\"https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_warning_API_token.png 991w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_warning_API_token-300x40.png 300w, https:\/\/robermb.com\/blog\/wp-content\/uploads\/2019\/06\/jenkins_warning_API_token-150x20.png 150w\" sizes=\"(max-width: 991px) 100vw, 991px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>Some interesting documentation:<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/jenkinsci\/docker\/blob\/master\/README.md\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">https:\/\/github.com\/jenkinsci\/docker\/blob\/master\/README.md<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Requirements: Ubuntu Server Linux with Docker installed. Tip: I have installed a virtual machine using the image: &#8220;ubuntu-18.04.2-live-server-amd64&#8221;. You can &hellip; <a href=\"https:\/\/robermb.com\/blog\/geeks\/how-to-install-jenkins-using-docker\/\" class=\"more-link\">More <span class=\"screen-reader-text\">How to Install Jenkins using Docker<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1629,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,8],"tags":[101,102],"_links":{"self":[{"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/posts\/1604"}],"collection":[{"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/comments?post=1604"}],"version-history":[{"count":33,"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/posts\/1604\/revisions"}],"predecessor-version":[{"id":1811,"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/posts\/1604\/revisions\/1811"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/media\/1629"}],"wp:attachment":[{"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/media?parent=1604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/categories?post=1604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robermb.com\/blog\/wp-json\/wp\/v2\/tags?post=1604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}