1、编写 Dockerfile
bash
# 使用Ubuntu 18.04作为基础镜像
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y \
build-essential \
curl \
zlib1g-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
ENV PYTHON_VERSION=3.10.8
RUN curl -O https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz \
&& tar -xf Python-${PYTHON_VERSION}.tar.xz \
&& rm Python-${PYTHON_VERSION}.tar.xz
RUN cd Python-${PYTHON_VERSION} \
&& ./configure --enable-optimizations \
&& make -j$(nproc) \
&& make install . \
&& cd - \
RUN rm -rf Python-${PYTHON_VERSION}
ENV PATH="/usr/local/bin:${PATH}"
2、构建Docker镜像,可自定义名称如:ubuntu1804_py310
bash
docker build -t ubuntu1804_py310 .
3、运行构建好的Docker镜像
bash
docker run -it ubuntu1804_py310 bash
4、保存Docker镜像到服务器(打tag)
docker tag ubuntu1804_py310:latest nexus.your_server.com:8082/ubuntu1804_py310:latest