基于commit命令创建docker镜像
创建docker容器
```Plain Text sudo docker run -it centos:centos7 /bin/bash
![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161142038.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161142038.png) ## 替换yum源
Plain Text
备份原来的源
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 https://mirrors.aliyun.com/repo/Centos-7.repo
生成缓存
yum makecache
![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161142604.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161142604.png) ## 安装和配置python3和django服务
Plain Text yum install -y python3 python3-pip
![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161142241.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161142241.png) ![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161143453.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161143453.png)
Shell
安装django
pip3 install django
创建django项目
django-admin startproject djangotest
修改配置文件
vim djangotest/djangotest/settings.py ALLOWED_HOSTS = ['*',]
![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161143016.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161143016.png) ## 编写启动脚本
Plain Text vi run.sh python3 /www/djangotest/manage.py runserver 0.0.0.0:8000 chmod +x run.sh
![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161143040.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161143040.png) ## 使用commit命令生成新镜像
Plain Text docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161143466.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202108161143466.png) ## 使用新镜像
Plain Text sudo docker run -p 10080:8000 -d centos:django sh /www/run.sh ```