In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to build an automated deployment environment for docker+jenkins+node.js". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Docker part
1.1introduction to docker
Docker is an open source application container engine that allows developers to package their applications and dependency packages into a portable container, publish them to any popular linux machine, and virtualize them. Containers completely use sandbox mechanism and will not have any interface with each other.
1.2.The docker architecture
Simply put, docker is a lightweight linux system. The docker container is created through a docker image. The relationship between containers and mirrors is similar to objects and classes in object-oriented programming. The docker architecture is shown in the figure:
1.3.The docker virtual machine management command
1.4. install docker
Update the software library
Yum update-y
Install docker
Yum install docker-y
1.5.Starting docker service
Start the docker service
Service docker start
Other related commands
Service docker restart / / restart docker service service docker stop / / stop docker service
2. Node part
You can write any hello-world project through the koa framework, and then create a new dockerfile file in the root directory of the project
Dockerfile is a text file that contains instruction, each of which builds a layer, so the content of each instruction is to describe how the layer should be built.
The author's own dockerfile file configuration information is as follows, which can be configured by those who are familiar with docker.
# dockerfile# uses node as a mirror from node# to create this directory in the container run mkdir-p / home/project# sets the container's working directory to the directory workdir / home/project# provides the command cmd npm install-- registry= https://registry.npm.taobao.org & & node. / start.js executed after the creation of the container at port 3000 expose 300
Publish the project to github to prepare for future jenkins deployment
3. Jenkins part
Query jenkins image
Docker search jenkins
Pull the latest jenkins image
Docker pull jenkins:latest
Start jenkins
Sudo docker run-d-u 0-- privileged-- name jenkins_node1-p 49003 purl 8080-v / root/jenkins_node1:/var/jenkins_home jenkins:latest
Command parsing:
-u 0
It refers to passing root account id to overwrite the built-in account in the container.
-v / root/jenkins_node1:/var/jenkins_home
Refers to mapping the directory / var/jenkins_home in the docker container to the host / root/jenkins_node1 directory
-- name jenkins_node1
Name the container jenkins_node1
-p 49003purl 8080
Port mapping, mapping port 8080 of the container to port 49003 of the host
-- privileged
Give the highest authority
The meaning of the whole order
Run a container mirrored as jenkins:latest, named jenkins_node1, overwrite the account in the container with root account, grant the highest permission, map the container's / var/jenkins_home to the host's / root/jenkins_node1 directory, and map port 8080 in the container to host 49003.
View jenkins
After the execution is complete, wait for dozens of seconds for the jenkins container to initiate initialization.
You can check whether there are too many files under the host / root/jenkins_node1.
Enter localhost:49003 in the browser to see if jenkins starts successfully.
The following interface indicates that the startup is successful:
Get the password
Cat / root/jenkins_node1/secrets/initialadminpassword
Copy the output password, paste it into the page, click continue to take you to the following page
Click install
Wait for the installation to complete and go to the interface of creating administrator account
Enter the account password information and click Save (to fill in the information) to go to the home page
Configure jenkins, go to the system management page, and manage plug-ins
Select the ssh plug-in
Install directly, wait for the installation to complete, go back to the home page
Go to system Management-> system configuration
Drag it to the bottom publish over ssh.
Select Advanced, enter the server ip, user name, password, and then click test configuration
Displaying success indicates that the configuration is fine. Then save it and go back to the home page
Create a new project
Enter project name
Select source code management, use git management, enter github warehouse address, and add github users
Finish and come to choose the build environment
Orders executed
Sudo docker stop nodeapp | | true\ & & sudo docker rm nodeapp | | true\ & & cd / root/jenkins_node1/workspace/node\ & & sudo docker build-- rm-- no-cache=true-t node-
< dockerfile \ && sudo docker run -d --privileged=true --name nodeapp -p 3000:3000 -v /root/jenkins_node1/workspace/node:/home/project node 保存后,点击立即构建 构建成功后,可以在宿主机的目录/root/jenkins_node1/workspace/node下看到你的项目文件了 在浏览器输入 docker服务器地址 localhost:3000 即可访问到页面信息 启动失败的,可以查看日志来确定一下失败的原因 docker logs nodeapp 4、jenkins + github自动部署 如果想本地代码提交push到github后,jenkins自动拉取最新代码重新部署,请继续看 服务器要外网能访问,本地环境想测试的可以尝试内网穿透 或者 在首页点击用户 首页 ->User-> root
Click Settings-> show api token
Copy the values in api token
Go back to the home page-> node-> configure-> build triggers to paste into the authentication token
Log in to your github project page and open setting-> webhooks-> add webhooks
Add webhooks
Modify the security policy of jenkins
On the home page of jenkins, select system Administration-> configure global security (the one below the system settings) to make the following settings
At this point, after the git push is complete, jenkins automatically builds the automatic deployment.
5. Common commands of docker
Those who are interested in docker can learn about it and continue to study.
Mirror correlation
Query image
Docker search [name]
Pull the image
Docker pull [name]
Import Mirror
Docker load
< /home/node.tar.gz 导出镜像 docker save >/ home/node.tar.gz
Query all mirrors
Docker images
Delete Mirror
Docker rmi [name]
Modify the image name
Docker tag docker.io/node node
Container dependence
Start
# run and enter interactive mode docker run-it-- name myjava java bash # run docker run-d-name myjava java in the background
Port mapping
Docker run-it-- name myjava-p 9000 java bash 8085-p 9000 Swiss 8086
Directory mapping
Docker run-it-name myjava-v / home/project:/soft-privileged docker.io/node bash
Enter the container running in the background
Docker exec-it name bash
Automatic restart
Docker run-- restart=always-it-- name myjava-p 9000 it 8085-p 9000 it 8086 java bash
Pause the container
Docker pause node
Stop pausing the container
Docker unpause node
Stop the container
Docker stop node
Start the container
Docker start-I node
View the container
Docker ps-a
Related to docker network segment
Create a network segment
Docker network create net1
View network segment information
Docker network inspect net1
Delete network segment information
This is the end of docker network rm net1's "how to build an automated deployment environment for docker+jenkins+node.js". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.