docker安裝jenkins 容器,集成python環境


 

1.docker安裝

# centos7 安裝docker
1 安裝依賴
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
2 設置docker yum源為阿里雲
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  
3 安裝
sudo yum install docker-ce -y
4.配置阿里雲加速器cd /etc/docker
daemon.json 文件
vim daemon.json
加入阿里雲加速器地址 72idtxd8隨便填
{ "registry-mirrors": ["https://72idtxd8.mirror.aliyuncs.com"] }
保存后,重啟docker拉取鏡像的速度嘎嘎的

2.安裝jenkins

docker pull jenkins/jenkins:lts  # 拉取鏡像
docker image ls -a    # 查看所有鏡像
docker image  inspect  鏡像id  # 查看jenkins的詳細信息及版本
mkdir /home/jenkins_home  # 創建一個jenkins映射目錄
docker run -itd --name=jenkins_01 -p 9090:8080 -v /home/jenkins_01:/home/jenkins_01 jenkins/jenkins:lts
解釋: i 運行容器 it 運行容器 並進入容器執行命令 itd 不會進入容器 --name 給容器起名字 -v 映射目錄

 

 進入容器

docker exec -it jenkins_01 bin/bash
cat /var/jenkins_home/secrets/initialAdminPassword

選擇安裝推薦的插件

 

 設置賬戶密碼 安裝完成

重啟:http://你的ip地址:9090/restart

 

安裝python3 環境

1.官網下載安裝包
https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz Python
-3.6.5_.tgz
2. copy 到容器中 或者進入容使用wget下載 在使用容器中使用wget下載比較慢時
docker cp Python-3.6.5_.tgz jenkins_01:/var/jenkins_home/python3

進入容器

docker exec -it -u root 容器id /bin/bash  #進入容器

換源阿里

查看系統,

cat /etc/issue

此時系統默認是debian 9系統,這里yum是沒有的,所以不能用yum安裝了,這里用apt-get代替yum,

root@cb8e397d5308:/# uname -a
Linux cb8e397d5308 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 GNU/Linux
root@cb8e397d5308:/# cat /etc/issue
Debian GNU/Linux 9 \n \l

Debian安裝軟件巨慢,換Debian源為阿里源

注意:  換源要對應strech

5是Debian      6是squeeze
7是wheezy      8是jessie
9是stretch
cat /etc/apt/sources.list

內容改為

deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib

更新apt-get

apt-get update

 jenkins 容器內安裝python

cd /var/jenkins_home/
mkdir python3
cd python3/
docker cp Python-3.6.5_.tgz jenkins_01:/var/jenkins_home/python3 # 從宿主機中copy到容器中
tar -xvf Python-3.6.5.tgz
cd Python-3.6.5
./configure --prefix=/var/jenkins_home/python3
 checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python3.6... no checking for python3... no checking for python... python checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... linux checking for --without-gcc... no checking for --with-icc... no checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/var/jenkins_home/python3/Python-3.6.8': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details

安裝gcc相關依賴

apt-get -y install gcc automake autoconf libtool make
apt-get -y install make*
apt-get -y install zlib*
apt-get -y install openssl libssl-dev
apt-get install sudo

make編譯安裝

在/var/jenkins_home/python3/Python-3.6.8目錄執行make和make install 安裝

./configure --prefix=/var/jenkins_home/python3 --with-ssl
make
make install

添加軟連接

添加python3軟鏈接

ln -s /var/jenkins_home/python3/bin/python3.6 /usr/bin/python3

添加pip3軟鏈接

ln -s /var/jenkins_home/python3/bin/pip3 /usr/bin/pip3

檢查環境

輸入pip3 和python3檢查環境

root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# pip3

root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# python3
Python 3.6.8 (default, Jan  1 2020, 10:15:14) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

使用pip3安裝一個requests包

pip3 install requests

pip 換源     

 vim  /etc/pip.conf  # 沒有就新建

修改內容為:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple 

這時候pip3 install requests 會很快

 

 

ssl問題

如果pip3安裝的時候遇到報ssl相關問題:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

這個是因為缺少ssl依賴包,網上的解決方案是yum install openssl-devel ,由於Debian系統沒有yum,用apt-get安裝

apt-get -y install openssl libssl-dev

安裝完成之后只能解決系統自帶的python2對應的pip安裝問題,無法解決python3的pip3安裝問題。

解決辦法:上面編譯的時候需加上參數 --with-ssl

./configure --prefix=/var/jenkins_home/python3 --with-ssl

重新執行make和make install 就可以了

也可以在python環境檢查是否能導入ssl

root@cb8e397d5308:/var/jenkins_home/python3/Python-3.6.8# python3
Python 3.6.8 (default, Jan  1 2020, 10:15:14) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl

 

 

git 拉取gitee 源碼 並構建

1.創建項目

 

 2.拉取git代碼   ssh  或 https

 

 

 

ssh: 方式1: 使用私鑰

 

 

 

 

ssh 方式二: 使用賬號密碼

 

 https: 

構建shell   :

補充解釋:jenkins的工作目錄: 

 

 

 

 

 進入容器:/var/jenkins_home/workspace/get_01

ls 查看,文件已上傳到jenkins的workspace目錄

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM