jenkins docker nginx proxy run

mushroomlb

mushroomlb

Posted on April 15, 2021

jenkins docker nginx proxy run

1 前提

linux环境

  • docker运行环境
  • nginx运行环境
  • 准备maven安装目录放到/opt/jenkins_docker/maven3
  • 新建宿主机映射目录 /opt/jenkins_docker
  • 准备nodejs安装目录放到  /opt/jenkins_docker/node-v14.16.1 ## 2 docker运行  docker方式运行命令如下:
docker run -d -p 28080:8080 --restart=always \
-p 10241:50000 \
-v /opt/jenkins_docker:/var/jenkins_home \
-v /etc/localtime:/etc/localtime:ro \
-v /opt/jenkins_docker/maven3:/usr/local/maven3  \
-e TZ=Asia/Shanghai \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker \
-v /opt/jenkins_docker/node-v14.16.1:/usr/local/nodejs \
--name myjenkins jenkins/jenkins
Enter fullscreen mode Exit fullscreen mode

各个参数的含义:

  • -d 后台运行
  • -p 28080:8080 对外暴露28080端口,防止端口冲突
  • --restart=always 在容器停止运行的时候,重启容器。用于开机自启和容器意外关闭时的自启动
  • -v /opt/jenkins_docker:/var/jenkins_home 将宿主机的 /home/jenkins-data 目录挂载到 /opt/jenkins_docker
  • -v /etc/localtime:/etc/localtime:ro 保证docker中的时区和宿主机一致
  • -e TZ=Asia/Shanghai  保证docker中的时区和宿主机一致
  • -v /opt/jenkins_docker/maven3:/usr/local/maven3  maven
  • -v /var/run/docker.sock:/var/run/docker.sock  容器与Docker守护进程通信
  • -v $(which docker):/usr/bin/docker  容器与Docker守护进程通信
  • -v /opt/jenkins_docker/node-v14.16.1:/usr/local/nodejs nodejs运行目录映射

3 nginx代理

  location / { 
    # 反向代理到 gitlab 内置的 nginx 
    proxy_pass http://10.19.42.165:28080; 
    proxy_set_header Host $Host:8080; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
  }
Enter fullscreen mode Exit fullscreen mode

4 配置全局环境

 jenkins 镜像中已经包含了jdk和git,在配置jenkins全局环境需要把路径找出来,配置下路径即可

先进入 jenkins 的容器中

docker exec -it jenkins容器id /bin/bash
Enter fullscreen mode Exit fullscreen mode

jdk

echo $JAVA_HOME
路径在/usr/local中,然后配置进 jenkins 的 JAVA_HOME 中即可

git

which git
Enter fullscreen mode Exit fullscreen mode

文件路径为/usr/bin/git,把这个复制到 jenkins 路径中

mvn 在运行时已经指定

/usr/local/maven3
Enter fullscreen mode Exit fullscreen mode

dokcer 在运行时已经指定

/usr/bin/docker
Enter fullscreen mode Exit fullscreen mode

nodejs 在运行时已经指定

/usr/local/nodejs
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
mushroomlb
mushroomlb

Posted on April 15, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related