构建python3.11+uv+openssh环境的docker镜像

发布于:2025-09-14 ⋅ 阅读:(21) ⋅ 点赞:(0)

        使用一个装有docker环境的Centos7系统上构建基础开发镜像,使其具有python3.11+uv+openssh的环境:

1、下载openssl,python源码包

# wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz

# wget https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tgz

2、编写Dockerfile构建

FROM centos:centos7.9.2009


RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime


RUN rm -f /etc/yum.repos.d/CentOS-Base.repo && curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& yum -y install epel-release vim net-tools telnet tree wget curl \
&& yum -y install zlib-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel \
&& yum -y install openssh-server openssh-clients \
&& yum clean all


RUN echo 'root:testdebug' | chpasswd &&\
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
sed -i 's/UsePAM yes/#UsePAM yes/' /etc/ssh/sshd_config && \
sed -i '/^#Port 22/c\Port 5222' /etc/ssh/sshd_config && \
ssh-keygen -A

RUN mkdir -p /opt/software && mkdir -p /usr/local/python3.11.2

ADD openssl-1.1.1w.tar.gz /opt/software

RUN cd /opt/software/openssl-1.1.1w && \
./config --prefix=/usr/local/openssl-1.1.1 --openssldir=/usr/local/openssl-1.1.1 shared zlib && \
make -j $(nproc) && \
make install && \
echo '/usr/local/openssl-1.1.1/lib' | tee /etc/ld.so.conf.d/openssl-1.1.1.conf && \
ldconfig


ADD Python-3.11.2.tgz /opt/software

RUN cd /opt/software/Python-3.11.2 && \
./configure --prefix=/usr/local/python3.11.2 --with-openssl=/usr/local/openssl-1.1.1 && \
make && make install


RUN mv /usr/bin/python /usr/bin/python2 \
&& ln -s /usr/local/python3.11.2/bin/python3 /usr/bin/python \
&& ln -s /usr/local/python3.11.2/bin/pip3 /usr/bin/pip3 \
&& ln -s /usr/local/python3.11.2/bin/pip3 /usr/bin/pip \
&& sed -i '1s/python/python2.7/g' /usr/bin/yum \
&& sed -i '1s/python/python2.7/g' /usr/libexec/urlgrabber-ext-down \
&& touch /etc/ld.so.conf.d/python.conf \
&& echo '/usr/local/python3.11.2/lib' >> /etc/ld.so.conf.d/python.conf \
&& ldconfig


RUN pip install --upgrade pip && \
pip install uv -i https://mirrors.aliyun.com/pypi/simple && \
ln -s /usr/local/python3.11.2/bin/uv /usr/bin/uv

RUN rm -rf /opt/software


EXPOSE 2222

CMD ["/usr/sbin/sshd", "-D"]

3、构建python3.11+openssh+uv基础镜像

docker build -t inrgihc/centos7.9.2009-openssh-python3.11-uv:basic .

docker push inrgihc/centos7.9.2009-openssh-python3.11-uv:basic