Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build the Docker host environment

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to build the Docker host environment". In the daily operation, I believe many people have doubts about how to build the Docker host environment. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to build the Docker host environment". Next, please follow the editor to study!

The environment demonstrated in this article involves three (class) servers, but only the configuration of the latter two types of servers is involved in this article:

Git server: 172.16.1.8, existing service for managing code

Docker host server: 172.19.10.157 to be built to run the docker container

Jenkins server: 172.19.10.232, to be built to run the Jenkins service.

Install and initialize Jenkins

The running environment of several JDK/MAVEN/TOMCAT software has been installed and configured in the Jenkins server. In this example, the versions of the above three software are: apache-maven-3.3.3, jdk1.7.0_09, tomcat-7.0.34, and all run under the operating system user tomcat.

Tip 1: the following actions are performed on the Jenkins server, unless otherwise specified, under the tomcat user.

Tip 2: before starting the tomcat service, it is recommended to modify the relevant environment variables to allocate appropriate memory space for the JAVA virtual machine through the JAVA_OPS parameter, so as to avoid memory overflow during Tomcat operation.

For example:

[tomcat@web01 ~] $vi / home/tomcat/tomcat-7.0.34/bin/catalina.sh

Add the following to the file header (considering the poor configuration of the local test server, so the allocated memory is small, you can modify the parameter values based on your actual situation):

JAVA_OPTS= "- server-Xms512M-Xmx1024M-XX:PermSize=128M-XX:MaxPermSize=256m-Dcom.sun.management.jmxremote-Duser.timezone=GMT+08-Djava.awt.headless=true"

The installation of Jenkins is very simple. The downloaded Jenkins is a war package that can be copied directly to the webapps directory of Tomcat to run.

So let's first download the latest version of jenkins and save it to the Tomcat application directory:

[tomcat@web01] $wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war-P / home/tomcat/tomcat-7.0.34/webapps

Start the tomcat service:

[tomcat@web01 ~] $tomcat-7.0.34/bin/catalina.sh start

Using CATALINA_BASE: / home/tomcat/tomcat-7.0.34

Using CATALINA_HOME: / home/tomcat/tomcat-7.0.34

Using CATALINA_TMPDIR: / home/tomcat/tomcat-7.0.34/temp

Using JRE_HOME: / home/tomcat/jdk1.7.0_60

Using CLASSPATH: / home/tomcat/tomcat-7.0.34/bin/bootstrap.jar:/home/tomcat/tomcat-7.0.34/bin/tomcat-juli.jar

Pay attention to the output log of tomcat during startup. The downloaded jenkins War will be decompressed and initialized automatically. The default administrator account and password information created during the process will be reflected in the log file, for example:

[tomcat@web01] $tail-100f tomcat-7.0.34/logs/catalina.out

.

Jan 21, 2017 13:04:11 PM jenkins.install.SetupWizard init

INFO:

* * *

* * *

* * *

Jenkins initial setup is required. An admin user has been created and a password generated.

Please use the following password to proceed to installation:

8c5abb9fcc7b4258aadac65ed5113b5a

This may also be found at: / home/tomcat/.jenkins/secrets/initialAdminPassword

* * *

* * *

* * *

.

INFO: Finished Download metadata. 20529 ms

.

Then access jenkins through the browser. If you are not logged in, you will jump to the login page. When you log in for the first time, you need to enter the password for initializing the account, which is the field we prompted in the log file earlier:

Enter the administrator password, click the Continue button, there will be an initialization process, you need to wait a few seconds, and then jump to the page of the optional plug-in, as shown below:

We choose the latter to install the required components in a custom manner.

By default, it also helps us select some essential / commonly used components (the label indicated by the red arrow above, which will be checked by default for the plug-in). On top of this, we have added some new components, mainly including:

? Git plugin: plug-ins that support building based on Git

? Git Parameter Plug-In: our software release is branch-based, not master-based. Through the Git Parameter plug-in, it is convenient for us to choose the branch version to build. Of course, if you do not have this requirement, you can not install this plug-in.

? GitLab Plugin: because our local Git is a set of private servers based on GitLab, we chose this component to trigger some operations related to automated build.

? Maven Integration plugin: release plug-ins for Maven2/3 projects

? Publish Over SSH: publish to another node based on SSH

? SSH plugin: the same as the above

Of course, you can also directly select all the plug-ins and install all the plug-ins, although there may be many plug-ins that are not available. In fact, I want to tell you that you don't have to worry too much about what plug-ins are installed and whether they are installed correctly or not, because we can call our installed plug-ins at any time according to our needs.

After selecting the plug-ins to install, click Install:

After that, you will have to wait for a while, and the time will vary depending on how many plug-ins you choose. After all the plug-ins have been installed, there is one more step to create an administrator account:

Then, you can see the main interface of Jenkins.

Second, set up a docker host

Tip: the following operations are performed on the docker host side, unless otherwise specified, under the root user.

Add a software installation source, and add the docker official address as the software installation source to the local tripartite source address. Edit the file as follows:

Root@docker01:~# vi / etc/apt/sources.list.d/docker.list

Just add one line:

Deb [arch=amd64] https://apt.dockerproject.org/repo debian-jessie main

Next, instead of executing apt-get, update the apt source to ensure that the latest resources are detected, as follows:

Root@docker01:~# apt-get update

If you encounter: e: The method driver / usr/lib/apt/methods/https could not be found. Then execute it first: # apt-get install apt-transport-https

You can then install docker through apt-get, with the following command:

Root@docker01:~# apt-get install docker-engine

Reading package lists... Done

Building dependency tree

Reading state information... Done

.

After the installation is successful, use the docker command to view the current docker version:

Root@docker01:~# docker-version

Docker version 1.13.1, build 092cba3

Next, let's create a dedicated user docker and set the initial password (also set to docker for demonstration convenience):

Root@docker01:~# useradd docker-d / home/docker-s / bin/bash-g docker

Root@docker01:~# echo "docker:docker" | chpasswd

The main purpose of this step is to configure ssh publishing in jenkins without directly using a user with super privileges such as root.

At this point, the image and container are empty.

Root@docker01:~# docker ps-a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Root@docker01:~# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Considering that the JAVA project we will run next will run in the tomcat container, we first pull a tomcat image as the basic image, and execute the command as follows:

Root@docker01:~# docker pull tomcat

Using default tag: latest

Latest: Pulling from library/tomcat

5040bd298390: Pulling fs layer

Fce5728aad85: Pulling fs layer

C42794440453: Pulling fs layer

9789263043d1: Waiting

6c6ea13aad15: Waiting

.

.

Digest: sha256:2c72f00904dc057441c388bb9101f7ca254174c9b061f99789e48bf495226deb

Status: Downloaded newer image for tomcat:latest

Root@docker01:~# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Tomcat latest 99765a0d7f44 14 hours ago 355 MB

At this point, the study on "how to build the Docker host environment" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report