前言
使用最基础的alpine镜像,构建满足自己需要的python3镜像
制作过程
本服务器环境基于centos7.5,系统环境(含docker环境,关闭firewalld及selinux等),请自行准备
存储镜像仓库
这里本作者使用在dockerhub申请的镜像仓库
如需申请,请自行进行dockerhub官网自行注册
- 登录镜像仓库
docker login --username=xxx
Password: # 输入账户密码
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
文件目录树结构
]# tree -aCg .
.
├── [root ] Dockerfile
├── [root ] get-pip.py
├── [root ] punish.sh
0 directories, 3 files
获取安装pip工具的py文件
编辑镜像Dockerfile文件
From alpine:latest
MAINTAINER techsharearea
RUN mkdir /install
COPY get-pip.py /install
RUN apk update && \
apk add curl && \
apk add vim && \
apk add tzdata && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
apk add python3 && \
python3 /install/get-pip.py && \
pip install sh requests
编辑构建镜像脚本
#!/usr/bin/env bash
NAME=techsharearea
TAG=apline:python3.8
TAG_LOCAL=${NAME}/${TAG}
docker build -t ${TAG_LOCAL} .
docker push ${TAG_LOCAL} # 推送至dockerhub镜像仓库
执行构建镜像脚本
bash punish.sh
结语
… …