docker部署jenkins安装使用教程_docker封装python程序

2022-09-16 11:10:45 浏览数 (1)

前言

使用docker安装jenkins环境,jenkins构建的workspace目录默认是在容器里面构建的,如果我们想执行python3的代码,需进容器内部安装python3的环境。

进jenkins容器

进docker容器, 加上-u root 以root用户权限进入容器

代码语言:javascript复制
docker exec -it -u root 容器id /bin/bash

查看当前操作系统cat /etc/issue

代码语言:javascript复制
root@3be4b6cd9b8c:/# uname -a
Linux 3be4b6cd9b8c 4.19.121-linuxkit #1 SMP Tue Dec 1 17:50:32 UTC 2020 x86_64 GNU/Linux
root@3be4b6cd9b8c:/# cat /etc/issue
Debian GNU/Linux 9 n 

这里查到的是Debian系统(不是ubuntu, 也不是centos),这里yum是没有的,所以不能用yum安装了,这里用apt-get代替yum 先执行更新apt-get

代码语言:javascript复制
apt-get update

容器内部安装python3环境

下载python3安装包

代码语言:javascript复制
root@3be4b6cd9b8c:/var/jenkins_home# cd /var/jenkins_home/
root@3be4b6cd9b8c:/var/jenkins_home# mkdir python3
root@3be4b6cd9b8c:/var/jenkins_home# cd python3/
root@3be4b6cd9b8c:/var/jenkins_home/python3# wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
root@3be4b6cd9b8c:/var/jenkins_home/python3# tar -xvf Python-3.76.tgz
root@3be4b6cd9b8c:/var/jenkins_home/python3# ls
Python-3.7.6  Python-3.7.6.tgz
root@3be4b6cd9b8c:/var/jenkins_home/python3# cd Python-3.7.6
root@3be4b6cd9b8c:/var/jenkins_home/python3/Python-3.7.6# ./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.7... 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.7.6':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

执行 ./configure –prefix=/var/jenkins_home/python3时报上面错:configure: error: no acceptable C compiler found in $PATH

apt-get 安装依赖包

这个是因为缺少gcc相关依赖包,使用apt-get代替yum安装相关依赖包

代码语言:javascript复制
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

由于python3.7以上版本在make install步骤中会出现缺少依赖(缺少_ctype)的错误提示,所以还需安装下面的依赖包

代码语言:javascript复制
sudo apt-get update
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
sudo apt-get install libxpm-dev libxext-dev 
sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev 

make编译安装

在/var/jenkins_home/python3/Python-3.7.6目录执行make和make install 安装

代码语言:javascript复制
./configure --prefix=/var/jenkins_home/python3 --with-ssl
make
make install

添加软链接

添加python3软链接

代码语言:javascript复制
ln -s /var/jenkins_home/python3/bin/python3.6 /usr/bin/python3

添加pip3软链接

代码语言:javascript复制
ln -s /var/jenkins_home/python3/bin/pip3 /usr/bin/pip3

输入pip3 和python3检查环境

代码语言:javascript复制
root@3be4b6cd9b8c:/# python3 --version
Python 3.7.6
root@3be4b6cd9b8c:/# pip3 --version
pip 19.2.3 from /var/jenkins_home/python3/lib/python3.7/site-packages/pip (python 3.7)
root@3be4b6cd9b8c:/# 

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/166320.html原文链接:https://javaforall.cn

0 人点赞