A一.基础环境搭建
1.docker私服搭建
参考 文档
// 用docker建立私有仓库
docker run -d -v /opt/module/docker-registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry
// 查看本机已有镜像
docker image ls
// 标记并上传
docker tag xxx:v 127.0.0.1:5000/xxx:v
docker push 127.0.0.1:5000/xxx:v
// 查询仓库里的镜像
curl 127.0.0.1:5000/v2/_catalog
// 删除本地镜像
docker image rm 127.0.0.1:5000/xxx:v
// 拉取仓库镜像到本地
docker pull 127.0.0.1:5000/xxx:v
二.构建
// 按根目录下Dockerfile文件打镜像
docker build -t 172.16.184.126:5000/ci-test .
// 推到docker私服
docker push 172.16.184.126:5000/ci-test
基础镜像选择
python:3.8-slim-buster
python:3.8-slim
python:3.8-alpine
Python应用,Docker基础映像到底哪个是王者? - 知乎 (zhihu.com)
构建自己的基础镜像
# syntax = docker/dockerfile:experimental
FROM centos:7
RUN set -ex \
# 替换yum源
&& mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup \
&& curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo \
# 安装python依赖库
&& yum makecache \
&& yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make wget \
&& yum clean all \
&& rm -rf /var/cache/yum \
# 下载安装python3
&& wget https://www.python.org/ftp/python/3.8.9/Python-3.8.9.tgz \
&& mkdir -p /usr/local/python3 \
&& tar -zxvf Python-3.8.9.tgz \
&& cd Python-3.8.9 \
&& ./configure --prefix=/usr/local/python3 \
&& make && make install && make clean \
#添加软链接
&& ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3 \
&& ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3 \
# 修改pip默认镜像源
&& mkdir -p ~/.pip \
&& echo '[global]' > ~/.pip/pip.conf \
&& echo 'index-url = https://pypi.tuna.tsinghua.edu.cn/simple' >> ~/.pip/pip.conf \
&& echo 'trusted-host = pypi.tuna.tsinghua.edu.cn' >> ~/.pip/pip.conf \
&& echo 'timeout = 120' >> ~/.pip/pip.conf \
# 更新pip
&& pip3 install --upgrade pip \
# 安装wheel
&& pip3 install --no-cache wheel \
# 删除安装包
&& cd .. \
&& rm -rf /Python* \
&& find / -name "*.py[co]" -exec rm '{}' ';' \
# 设置系统时区
&& rm -rf /etc/localtime \
&& ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime