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 install jenkins container in docker environment

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

Share

Shulou(Shulou.com)06/02 Report--

What the editor wants to share with you this time is how to install the jenkins container in the docker environment. The article is rich in content, and interested friends can learn about it. I hope you can get something after reading this article.

1. Docker installation in Centos7 environment

First go to the official website to download the image

1. The latest installation

Yum install-y yum-utils device-mapper-persistent-data lvm2

two。 Join docker Feed

Yum-config-manager-- add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3. Install docker

Yum install docker-ce

Note: check if docker is installed?

Yum list installed | grep docker

If you want to uninstall, you can enter the command:

Yum remove xxx xxxx xxx

4. Set dns, accelerator and bind ip in / etc/docker/daemon.json. In general, there is no daemon.json file, so you need to create it yourself.

{"dns": ["114.114.114.114", "8.8.8.8"], # Accelerator, which can increase the speed of downloading images. Here you can also configure the image address "registry-mirrors" of Aliyun: ["https://registry-docker.com"]," bip ":" 172.17.5.1 shock 24 "}.

5. After installation, check the docker version and information

Docker versiondocker info

6. Set docker to start when the virtual machine starts

Sudo chkconfig docker on

7. Start docker

Sudo service docker start

II. Install Jenkins for docker

1. Generally, in order to facilitate management, customize the ip segment of the container. Here I customize my network name: mynetwork

Docker network create-subnet=172.18.0.0/16 mynetwork

When the definition is complete, you can see: docker network ls

two。 Download the jinkins image:

Format: docker pull image: version number. If the version number is not specified, the latest version number: latest will be downloaded by default.

Docker pull jenkins/jenkins:latest

3. Authorize the container account

In order to prevent jinkins from having to reinstall Jenkins when migrating or recreating the container, you need to mount data to the corresponding directory during the first installation. In my case, I mount the data to this directory: / home/docker/data/jenkins. Since the container account corresponds to 1000 in the host, you need to authorize the mount directory / home/docker/data/jenkins, otherwise the creation of the container will fail when it starts:

Chown-R 1000 / home/docker/data/jenkins

4. Create a container and start it with linux startup, and specify a fixed ip

Docker run-- net mynetwork-- ip 172.18.0.4-v / home/docker/data/project/jenkins:/home/docker/data/jenkins-v / home/docker/var/jenkins/jenkins_home:/var/jenkins_home-v / etc/localtime:/etc/localtime-e JAVA_OPTS=-Duser.timezone=Asia/Shanghai-dit-- name my-jenkins-p 808080 8080-p 50000-- restart=always jenkins/jenkins:latest

Explanation:

1. Murv / home/docker/data/project/jenkins:/home/docker/data/jenkins

This directory is mounted to facilitate the writing and execution of scripts on the host, and the jenkins container can also call

2. Murv / home/docker/var/jenkins/jenkins_home:/var/jenkins_home

This directory is mounted to facilitate Jenkins migration and does not need to be reinstalled

Note: the port number of-p 50000 50000 should be defaulted and not modified. Only the port number of-p 8080R 8080 can be set according to our own needs.

6. Installation succeeded, check out:

Docker ps-a | grep jenkins

5. Enter the container:

For root users:

Docker exec-it-u root my-jenkins / bin/bash

Default user: docker exec-it my-jenkins / bin/bash

6. Install the vim command in the container for the first time:

Apt-get updateapt-get install vim

7. There are two ways to exit the container:

1) exit

2) Ctrl + P + Q

After reading this article on how to install jenkins containers in docker, if you think the article is well written, you can share it with more people.

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