How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC

What made you decide to write this article

The Udemy course below uses VirtualBox, CentOS7, and Docker, so I created it because I wanted to remember the procedure. 【Jenkins, From Zero To Hero: Become a DevOps Jenkins Master】


You need to install VirtualBox, Docker, and download the ISO of CentOS7, but the procedure changes every time a new one comes out, and even if it is an article, it will often not be usable after a few months, so I will omit it and only the version will be posted. VirtualBox 6.1.14 platform packages Docker 19.03.12 Docker Compose 1.26.2 CentOS-7-x86_64-Minimal-1810.iso ※ There is an ISO of CentOS in, so click it to download it.

Target readers

mac user Udemy's Jenkins, From Zero To Hero: Become a DevOps Jenkins Master course for those who didn't understand what they were saying

How to build a CentOS virtual environment on VirtualBox

スクリーンショット 2020-09-08 0.23.23.jpg

Click New.

スクリーンショット 2020-09-08 0.25.22.jpg

Name Jenkins

Type is Linux The version is Red Hat (64-bit) To The reason for changing the version to Red Hat (64-bit) is that CentOS is Red Hat series Linux and CentOS-7-x86_64-Minimal-1810 is for 64bit.

Click Continue.

スクリーンショット 2020-09-08 0.28.58.jpg

The memory size is displayed. Set it to 2048MB and click.

スクリーンショット 2020-09-08 0.30.59.jpg

Select Create virtual hard disk and click Create.

スクリーンショット 2020-09-08 0.31.47.jpg

Select VDI and click Continue.

スクリーンショット 2020-09-08 0.32.32.jpg

Select a variable size and click Continue.

スクリーンショット 2020-09-08 0.34.04.jpg

The above pass is not particularly tampered with. Make the size 20GB.

Click Create.

スクリーンショット 2020-09-08 0.35.44.jpg

I was able to build an environment for building a Jenkins server.

Click Settings to open the network. スクリーンショット 2020-09-08 0.36.55.jpg

Change the adapter 1 assignment from NAT to bridge adapter. The name may differ from person to person ... My house is connected to the network via Wi-Fi, so I set en0, which is Wi-Fi. The wired one is probably Ethernet ...?

スクリーンショット 2020-09-08 0.38.36.jpg

Click OK when you are done.

スクリーンショット 2020-09-08 0.40.52.jpg

Click Start ... and before that, there are a lot of people who can't move the mouse cursor in VirtualBox. The solution is to press the left Command key once, so be sure to remember that and move on to the next step. The timing of onset is different for each person. Now take a second and click Launch.

Some people need to set security and privacy here, so I'll allow you to monitor the input from the keyboard of

スクリーンショット 2020-09-08 0.43.08.jpg

After completing the settings, restart VirtualBox and start the Jenkins virtual environment again.

スクリーンショット 2020-09-08 0.45.13.jpg

Some people also have to allow privacy, so check this as well and restart VirtualBox again.

スクリーンショット 2020-09-08 0.49.35.jpg

Specify the CentOS 7 ISO (CentOS-7-x86_64-Minimal-1810.iso) downloaded here, but it is Empty (empty). You need to specify it, so click the folder on the right. Click Add to navigate to the location where you saved the ISO and select it. Click Choose.

スクリーンショット 2020-09-09 1.20.30.jpg

Click Start.

スクリーンショット 2020-09-08 0.56.04.jpg

Use the up and down keys to select, and the Return key to confirm. Move the cursor to Install CentOS7 and press the Return key.

スクリーンショット 2020-09-08 1.01.35.jpg

The installation of CentOS7 will start, so wait for a while. It will end unexpectedly soon.

スクリーンショット 2020-09-08 1.02.37.jpg

Language setting. Select Japanese and click Continue.

スクリーンショット 2020-09-08 1.04.33.jpg

スクリーンショット 2020-09-08 1.05.05.jpg

Scroll down.

スクリーンショット 2020-09-08 1.05.52.jpg

Auto party ... Click selected.

スクリーンショット 2020-09-08 1.07.12.jpg

Click Finish without touching anything.

スクリーンショット 2020-09-08 1.08.07.jpg

Then, the △ </ font> mark disappeared.

Then click Network and Hostname.

スクリーンショット 2020-09-08 1.16.43.jpg

Click Ethernet (enp0s3) in the upper right.

スクリーンショット 2020-09-08 1.17.14.jpg

Click Finish when you are done.

スクリーンショット 2020-09-08 1.08.07.jpg

Click Start Installation.

スクリーンショット 2020-09-08 1.09.21.jpg

Click the ROOT password to create the ROOT password.

スクリーンショット 2020-09-08 1.11.59.jpg

Here, the password is set to 123456 for the sake of clarity.

スクリーンショット 2020-09-08 1.12.18.jpg

Click Finish twice as you type.

スクリーンショット 2020-09-08 1.19.53.jpg

Next, create a user.

スクリーンショット 2020-09-08 1.21.03.jpg

Enter as shown in the image below. The full name should be jenkins. The user name is automatically entered each time you enter the full name. If you make this user an administrator, don't forget to check Require password to use this account. Leave the password at 123456.

スクリーンショット 2020-09-08 1.22.12.jpg

When you're done, click Done in the upper left twice.

Then wait until the installation is complete.

スクリーンショット 2020-09-08 1.22.53.jpg

When you're done, click Finish Settings at the bottom right.

スクリーンショット 2020-09-08 1.25.24.jpg

Click Reboot when you're done.

スクリーンショット 2020-09-09 1.33.37.jpg

Change Settings → Display → Graphics Controller from VMS VGA to VBox VGA. * It took a whole day to fix this.

スクリーンショット 2020-09-09 1.41.38.jpg

It says that an invalid setting was found, but that's okay. Press OK to start again.

Even if the ISO selection screen appears at startup, you can cancel it.

スクリーンショット 2020-09-09 1.43.24.jpg

CentOS 7 has started successfully. localhost login:jenkins password:123456 Log in with.

Remember the shortcut key for clearing the screen


If you type the command, all the characters will disappear, but it is inefficient, so be sure to remember the shortcut key. With Command + l, the same operation as the clear command is performed.

スクリーンショット 2020-09-09 1.57.23.jpg

Find out the IP address

ip a

You can find out the IP address by typing.

スクリーンショット 2020-09-09 1.58.49.jpg

Looking at the inet of enp0s3, it is This will be the IP address of this virtual environment.

Set to access with terminal

With VirtualBox Manager open, select File ® Host Network Manager.

[File tab] スクリーンショット 2020-09-09 2.08.07.jpg

スクリーンショット 2020-09-09 2.08.43.jpg

Click Create.

スクリーンショット 2020-09-09 2.09.14.jpg

Make sure the IP address is Confirm that vboxnet0 has been created and click Close. I think everyone will have the same IP address, but if they are different, you will need to replace the IP address used in the following steps.

Set the host-only adapter in the VM settings → network → adapter 2 created earlier.

スクリーンショット 2020-09-09 2.10.38.jpg

Click OK.

Start the virtual environment and log in. localhost login:jenkins password:123456

Execute the nmtui command. This command is a command that allows you to visually configure network settings instead of commands. It's called the Iwaruyu GUI. It seems that you can do it with a command, but I will omit the method. It's a hassle to open various files and edit them with vi text.

スクリーンショット 2020-09-09 2.13.34.jpg

The nmtui screen is operated with the up and down keys and the Return key. Use the up and down keys to move and select Edit a connection with the Return key.

スクリーンショット 2020-09-09 2.14.10.jpg

Select enp0s3 with the Return key.

スクリーンショット 2020-09-09 2.15.04.jpg

Change IPv6 to Ignore with the Return key. It is OK if you can confirm that Automatically connect is [X].

Place the cursor on OK and select.

Then select * * * * *. (Actually, it should be enp0s8, but there is a bug. My acquaintance also displayed the same.)

スクリーンショット 2020-09-09 2.17.13.jpg

If the Profile name is buggy, leave it as enp0s8. Change Ipv4 CONFIGURATION to Manual and Addresses to

スクリーンショット 2020-09-09 2.19.16.jpg

Then change Ipv6 to Ignore. It is OK if you can confirm that Automatically connect is [X].

スクリーンショット 2020-09-09 2.20.46.jpg

Select OK and exit with Back → Quit.

Then enter the following command.

service NetworkManager restart
service network restart
  • When prompted for a password, enter 123456.

Now you're ready to access VirtualBox's CentOS from your mac using terminal.

Access with terminal.

Open the spotlight search with Command + Space, type and enter the Return key to launch terminal. It's a strength of mac that is different from Windows.

For Windows, I think you should use putty or teraterm. (I don't think Windows is looking at it because I think the procedure up to this point is quite different from Windows ...)

Enter the following command to make an ssh connection with terminal.

ssh [email protected]

Enter 123456 when prompted for a password.

スクリーンショット 2020-09-09 2.25.54.jpg

Then you can access Centos on VirtualBox with terminal. Now, after that, if you start the virtual machine with VirtualBox, start CentOS, and minimize it appropriately, you can operate Centos from the mac side. It's difficult to operate on the screen displayed in VirtualBox.

Check if the yum command can be used

Run yum list as a trial. Originally, after the yum update started, the software installed by yum is displayed in a list, but an acquaintance wrote an article when it did not work.

I did it without doing anything, but if it doesn't work, please refer to it.

Install Docker

Check if you can connect to the network once.


スクリーンショット 2020-09-12 20.45.09.jpg

If connected, it will look like the image. The log will continue to flow endlessly, so press Control + c to interrupt it.

スクリーンショット 2020-09-12 20.46.19.jpg

Search google for docker for centos and open the Install Docker Engine on CentOS | Docker Documentation web page.

スクリーンショット 2020-09-12 20.47.19.jpg

スクリーンショット 2020-09-12 20.48.35.jpg

Based on this page, enter commands one after another from the top. I will post the command for the time being, but the command on the official homepage changes every day, so the command may be completely different.

First, uninstall the old version of Docker (there is no point in doing it without Docker)

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

I get a lot of logs saying that the arguments do not match. In other words, docker is not installed.

Next, install the software yum-utils that makes yum convenient.

sudo yum install -y yum-utils

Next, create a repository for docker.

sudo yum-config-manager \
    --add-repo \

You have now created docker-ce.repo in the following directory: /etc/yum.repos.d ┗docker-ce.repo

Finally, I've come to the point of installing docker. Do the following:

sudo yum install docker-ce docker-ce-cli

It's okay to stop in the middle. It's searching for a mirror site. Therefore, please refrain from key input. If you enter it, the installation will be interrupted and you will need to execute the command again. (I did it once) If [y / d / N] or [y / N] appears on the way, enter y to proceed.

スクリーンショット 2020-09-12 21.13.41.jpg

Finally completed! Is displayed, Docker installation is complete. スクリーンショット 2020-09-12 21.14.10.jpg

Start docker.

sudo systemctl start docker

スクリーンショット 2020-09-12 21.17.21.jpg

Nothing happens, but it's okay.

Although it is not in the command collection on the official website, it executes the command to start Docker automatically at startup.

sudo systemctl enable docker

スクリーンショット 2020-09-12 21.20.37.jpg

To check if docker is installed, try displaying the docker process with the following command.

docker ps

スクリーンショット 2020-09-12 21.25.07.jpg

Right now I'm running it as an administrator so it works fine, but I think I created the jenkins user when installing CentOS. I change the user to the jenkins user using the su command there, and when I run docker ps, it fails because I don't have permission. Therefore, execute the following command so that it can be executed.

sudo usermod -aG docker jenkins

To reflect that setting, disconnect the ssh connection once with exit and connect again with ssh. Now the jenkins user can also run docker ps and work.

Install docker compose

Search google for docker compose installation.

スクリーンショット 2020-09-12 21.28.57.jpg

Install Install Docker Compose | Open Docker Documentation.

スクリーンショット 2020-09-12 21.28.53.jpg

If you go down a little, there are tabs such as mac and Windows, so select Linux.

スクリーンショット 2020-09-12 21.30.24.jpg

Enter the command displayed there. This also changes every day, so it is better to refer to the official sail, but I will post the command for the time being.

docker compose installation command

sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

It will end soon.

スクリーンショット 2020-09-12 21.32.50.jpg

As per the command, docker-compose will be installed in / usr / local / bin.

スクリーンショット 2020-09-12 21.37.08.jpg

I moved the directory with cd, displayed the path with the pwd command, and displayed the partition (the one with -rw-r--r--) with the ll command.

Since you do not have execute permission, you do not have execute permission for docker-compose as it is. Therefore, grant execute permission.

You can grant execute permission by executing the following command.

sudo chmod +x /usr/local/bin/docker-compose 

スクリーンショット 2020-09-12 21.38.48.jpg

The partition has changed from -rw-r--r-- to -rwxr-xr-x! This means that you have been granted execute permission.

If docker-compose is installed, you can view the version, so check that way.

docker-compose -v

スクリーンショット 2020-09-12 21.40.56.jpg

It's docker-compose version 1.27.1. Installation is successful.

Build a jenkins server using docker

Google search for docker jenkins image.

スクリーンショット 2020-09-12 21.53.45.jpg

Open jenkins / jenkins. This is a Docker image maintained by the jenkins team. The one with jenkins is the official image, but be careful because this is a mistake!

スクリーンショット 2020-09-13 0.35.29.jpg

Then, the command to install is on the right side, so copy and paste it and execute it on the terminal. * I will do it while logged in to CentOS with ssh connection

docker pull jenkins/jenkins

スクリーンショット 2020-09-12 21.57.24.jpg

docker images

スクリーンショット 2020-09-12 21.58.24.jpg

docker info

スクリーンショット 2020-09-12 22.00.49.jpg

Make sure you have the jenkins Docker image with the following command. As an aside, where is the Docker data? You can find out by viewing the Docker information. A lot of information is displayed. The root directory of docker is written in this, but it is difficult to find. Therefore, you can quickly find it with the following command.

docker info | grep -i root

The grep command is useful for searching for strings. From the character string displayed by docker info, the line containing root is extracted and displayed. By adding -i, you can search in a case-insensitive manner.

スクリーンショット 2020-09-12 22.03.19.jpg

I was able to confirm that / var / lib / docker is the root directory of Docker. Docker related data is stored in this.

Next, create a directory to store jenkins data. Create it in the form / home / jenkins / jenkins. First, move to the home directory, create a jenkins directory, and then create a jenkins directory in it.

cd /home
mkdir jenkins
cd jenkins
mkdir jenkins

スクリーンショット 2020-09-12 22.22.00.jpg

You have now created a jenkins directory. Finally, the pwd command is used to display the current directory.

For practice, try renaming the directory using the mv command.

Before correction




Execute the following command.

cd /home
cd jenkins
mv jenkins jenkins-data
cd jenkins-data

スクリーンショット 2020-09-12 22.25.11.jpg

I was able to change the directory name safely.

Next, create docker-compose.yml in / home / jenkins / jenkins.

Execute the following command to create a new file.

vi docker-compose.yml

スクリーンショット 2020-09-12 22.28.02.jpg

To briefly explain vi, the default is normal mode that accepts commands, you can enter characters in insert mode with i, cancel insert mode with esc and enter normal mode, and press ": wq" in normal mode When executed, it saves and exits, closes with ": q", and forcibly terminates without saving with ": q!". If you have this much knowledge, I think you can do something about it. Maybe.

I will write more and more with vi. First, specify version 3.


version: '3'

Next, specify the container name of jenkins.


version: '3'
    container_name: jenkins

Specify the Docker image. This specifies the image name described in the Repository when docker images are executed. I think it's a good idea to make a habit of writing after confirming it.


version: '3'
    container_name: jenkins
    image: jenkins/jenkins

Then specify the port. Since jenkins is an http server, set it to 8080. The left side is the port number of the jenkins server, and the right side is the port number when accessing with mac.


version: '3'
    container_name: jenkins
    image: jenkins/jenkins
      - "8080:8080"

Next, create a volume. Docker has the concept of volumes. If you create a Docker container and then destroy it, all the data on the container will be blown away. What if I have data that I don't want to blow away? The answer is to save it to a volume. For now, it would be good if there was that much recognition. Press the esc key once to switch from insert mode to normal mode, save with: wq, exit, and create space for the volume. Make sure you are in the following directory:


Next, create the jenkins_home directory, which is the area for the volume.

mkdir jenkins_home

Inside, you can store the data on your Docker container. Once created, go back to editing docker-compose.yml.

vi docker-compose.yml

Specify the volume. The left is the directory created earlier (copy destination), and the right is the directory on the Docker container (copy source). The information that the directory on the right is / var / jenkins_home instead of / var / lib / jenkins_home is out of date.


version: '3'
    container_name: jenkins
    image: jenkins/jenkins
      - "8080:8080"
      - "$PWD/jenkins_home:/var/lib/jenkins_home"

Next, write four lines of information about the network. One is under jenkins: and the other is under docker-compose.yml.


version: '3'
    container_name: jenkins
    image: jenkins/jenkins
      - "8080:8080"
      - "$PWD/jenkins_home:/var/lib/jenkins_home"
      - net

The final form is as follows.


version: '3'
    container_name: jenkins
    image: jenkins/jenkins
      - "8080:8080"
      - "$PWD/jenkins_home:/var/lib/jenkins_home"
      - net

スクリーンショット 2020-09-12 23.10.56.jpg

Press the esc key to return to normal mode and press: wq to save.

When you're done, change the permissions on the jenkins_home directory.

sudo chown 1000:1000 jenkins_home -R

Go to the directory where docker-compose.yml is located and start the docker container.

docker-compose up -d

The trailing -d means run in the background.

スクリーンショット 2020-09-12 23.12.04.jpg

Execute the following command.

docker ps

スクリーンショット 2020-09-12 23.29.35.jpg

The Jenkins server is now running on the Docker container.

[If not displayed]
If jenkins is displayed with the following command
Failed to start Docker container.
docker ps -a

You can view the log with the following command,
You can investigate the cause of the error.
docker-compose logs jenkins

The volume on the Docker container side/var/lib/jenkins_home
not,/var/jenkins_If the information that is home is old
As I wrote earlier, it is by displaying this log
I came to a solution.

Since the password generated by jenkins is required, execute the following command to display the log with docker.

docker logs -f jenkins

スクリーンショット 2020-09-12 23.34.39.jpg

You will see the words "1a193f6a36674f58856aed0b3041bc13", copy it and make a note of it.

This is the last spurt.

What was the CentOS IP address on VirtualBox? Yes, it was Now, attach the port number 8080 that indicates the http server to it, and enter "" in the URL of your web browser.

スクリーンショット 2020-09-12 23.41.57.jpg

Can you go ...?

スクリーンショット 2020-09-12 23.42.12.jpg

I was able to access jenkins safely ~! Mammoth happy!

Now you can build a Jenkins server in VirtualBox CentOS 7 with a Docker container and access the Jenkins server from your local PC.

To finish, paste the 1a193f6a36674f58856aed0b3041bc13 you noted earlier and make sure you can access it. (This string varies from person to person!)

スクリーンショット 2020-09-12 23.43.53.jpg

Sounds okay. How to use Jenkins is explained below. If you like, please read this as well.

What is Jenkins? ] I will explain from the installation of Jenkins to how to use it in the world's easiest way

Recommended site for studying docker

I haven't explained about docker in particular this time, but I highly recommend it because the following sites are easy to understand!

Fox planet

Recommended Posts

How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
How to share on the host side (windows) and guest side (CentOS 7) with VirtualBox
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
[Docker] How to see the contents of Volumes. Start a container with root privileges.
[Docker] How to access the host from inside the container. http://host.docker.internal:
I tried to build the environment of PlantUML Server with Docker
Make a daily build of the TOPPERS kernel with Gitlab and Docker
Access MySQL on a Docker container from a local (host OS) Java program
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
[Docker] How to build when the source code is bind-mounted on the container
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
How to get a heapdump from a Docker container
Connect with VS Code from a Windows client to Docker on another server
How to use Eclipse on my PC with 32bit and 2GB of memory
How to deploy to Heroku from a local docker image
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
Build a CentOS 8 virtual environment on your Mac with VirtualBox
Build a Node-RED environment with Docker to move and understand
How to run React and Rails on the same server
Easily convert Java application to Docker container with Jib ~ Build with gradle and register in local repository
[Docker] How to back up and restore the DB data of Rails application on docker-compose [MySQL]
How to set the IP address and host name of CentOS8
Build a NAS with DLNA function at the speed of a second with Raspberry Pi and Docker Compose
A story of connecting to a CentOS 8 server with an old Ansible
How to build an environment with Docker, which is the minimum required to start a Rails application
Let's create a Docker container that can connect to CentOS 8 with the minimum configuration by SSH
How to place and share SwiftLint config files on the server
Install Ubuntu20.04 on RaspberryPi 4 and build Kubernetes to run the container
Build a container version of Minecraft server and use https-enabled Dynmap
Use Jenkins to build inside Docker and then create a Docker image.
A story that I was addicted to twice with the automatic startup setting of Tomcat 8 on CentOS 8
How to download and run a Jar package directly from the Maven repository with just the command line
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
How to interact with a server that does not crash the app
[Java] How to retrieve the parameters passed from html on the server side
How to build a Ruby on Rails environment using Docker (for Docker beginners)
How to check before sending a message to the server with Spring Integration
Starting with installing Docker on EC2 and running Yellowfin in a container
How to access Socket directly with the TCP function of Spring Integration
Run x11 apps in a Docker container (supports network access from the container)
How to solve the local environment construction of Ruby on Rails (MAC)!
How to start a Docker container with a volume mounted in a batch file
Build DNS server with CentOS8 and bind
How to build Rails 6 environment with Docker
How to mount the batch file location via WSL2 and start the Docker container
How to get the ID of a user authenticated with Firebase in Swift
How to display the amount of disk used by Docker container for each container
Up to the point of launching a Docker container built using RedHat Quarkus
Monitor the Docker container and SystemD process on the same host with Zabbix on Ubuntu.
How to add a virtual disk to Linux (CentOS7) on VirtualBox to free up space
How to build an environment of [TypeScript + Vue + Express + MySQL] with Docker ~ Vue edition ~
How to find the distance and angle between two points on a plane
Build a development environment to create Ruby on Jets + React apps with Docker
How to start with Hyper-V instead of WSL2 on Docker Desktop for Windows
A quick note on using jshell with the official Docker image of the JDK
How to check the logs in the Docker container
How to deploy a container on AWS Lambda
Setting to exit from Docker container with VScode
How to build API with GraphQL and Rails
[Rails] How to build an environment with Docker
How to build a Pytorch environment on Ubuntu