安装一个python小项目
制作一个python程序制作成image并运行成container
安装python3依赖的安装包,这里我选择Python-3.9.0源码包
https://www.python.org/downloads/
解包,编译安装
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
tar -xzvf Python-3.9.0.tgz -C /usr/local/src/
cd /usr/local/src/Python-3.9.0
./configure --prefix=/usr/local/python3
make && make install
添加环境变量
cd /etc/profile.d/
export PATH="$PATH:/usr/local/python3/bin"
source ../profile
echo $PATH
正式制作:
环境准备:
pip3 install flask
python可执行项目:
app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello()
return "hello docker"
if __name__ == '__main__'
app.run()
目录结构:
先拉一个python镜像环境
docker pull python
docker run -itd python:latest bash
docker exec -it 01ce8524a4cb bash
vim Dockerfile
FROM python
LABEL maintainer="Jiahao li<ljh*******@163.com>"
RUN pip3 install flask
COPY app.py /app/
WORKDIR /app
EXPOSE 5000
CMD ["python3","app.py"]
制作镜像:
docker build -t lijiahao0302/flask-hello-word .
运行容器:
docker run -d lijiahao0302/flask-hello-word
发布者:LJH,转发请注明出处:https://www.ljh.cool/5203.html