1、下载基础镜像
# 这里以centos7为例
docker pull centos:centos8
2、生成requirements.txt
1、pip freeze > requirements.txt
这种会将所有的包都生成
2、使用
# 安装
pip install pipreqs
# 在当前目录生成
pipreqs . --encoding=utf8 --force
注意 --encoding=utf8 为使用utf8编码,不然可能会报UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 406: illegal multibyte sequence 的错误。
--force 强制执行,当 生成目录下的requirements.txt存在时覆盖。
3、基础镜像已经准备好了,接下来准备好需要部署的环境服务,以python项目,项目目录下:
### 创建 dockerfile 文件
mkdir dockerfile &&<