Docker install Jenkins

1. Install docker
2. Install docker-compose
3. Create directory /home/chengf/jenkins
4. Create data volume
docker volume create --name jenkins_data

5. Download and install JDK1.8 on the docker host host, if it is a maven project, you also need to download and install maven
6. Install and start Jenkins
docker run --name chengf_jenkins -d -p 8080:8080 -p 50000:50000 -v jenkins_data:/var/jenkins_home -v /home/chengf/soft/jdk1.8.0_111:/usr/local/jdk -v /home/chengf/soft/apache-maven-3.3.9:/usr/local/maven -v /home/chengf/.m2:/var/jenkins_home/.m2 jenkins

  • -v jenkins_data:/var/jenkins_home hangs the Jenkins home directory to the newly created valume
  • -v /home/chengf/soft/jdk1.8.0_111:/usr/local/jdk Mount the jdk on the host into the Jenkins image, so that it can be used without installing JDK inside Jenkins
  • -v /home/chengf/soft/apache-maven-3.3.9:/usr/local/maven Mount maven on the host into the Jenkins image
  • -v /home/chengf/.m2:/var/jenkins_home/.m2 jenkins mounts the .m2 file on the host to the .m2 in Jenkins, so that if we need to configure properties such as maven private servers, we can directly configure the host On the .m2/setting.xml file

7. Install the Jenkins plugin You
need to install the Maven Integration plugin, GitLab Plugin, and Gitlab Hook Plugin. If the direct installation fails, you can download it first, and then in advance, select the downloaded plugin and upload it and install it.



8. Set the Jenkins time
* and run it directly The date of the Jenkins image may be inaccurate, and the internal image cannot be set by date -s. This problem can be solved by setting the timezone of the host into the image, that is, appending to the startup script.

-v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone 



9. Use Jenkins to directly generate a docker image

Because the Jenkins image only contains a basic linux operating environment, you cannot directly run commands such as docker build in it, so you need to use the Publish over SSH plug-in to deliver the jar with the Jenkins image. Go to a formal linux environment and generate an image through the ssh command, the specific steps

  • Install Publish over SSH
  • configure ssh server
  • 1. Passphrase: your passphrase
     2. path to key: blank
     3. key : blank
     4. Disable exec : un-check
    SSH Servers
    
    1. Name: [email protected]
     2. hostname: remotehost.com
     3. Username: remote_user
     4. Remote Directory: your remote directory
    Advanced --
    
    5. check the box "use passsword authentication, or use a different key"
        `important`
    
     6. Passphrase / Password: your linux login password`important`
    
     7. path to key: blank
    
     8. key:blank
    
     9. port: ssh server's ssh port(default 22)
    
     10. Timeout(ms): 300000
    



  • Project Configuration Post Steps




  • In this way, you can use the docker command on the ssh server to directly generate the docker image, and upload the image file to your own private server. Because the docker repository and the ssh server in my environment are the same machine, the generated image name is localhost , if it is different, it needs to be changed to the ip of the corresponding docker repository

    Guess you like

    Origin http://10.200.1.11:23101/article/api/json?id=326712237&siteId=291194637