1.Python镜像

1.1Dokcerfile
FROM python:3.6 # 创建目录 RUN mkdir /usr/src/app # 将当前目录下的文件全部复制过去,只有是复制项目,uwsgi配置文件 COPY . /usr/src/app/ # 设置工作目录 WORKDIR /usr/src/app # 更新pip RUN pip install --upgrade pip RUN pip install -i https://pypi.doubanio.com/simple/ -r /usr/src/app/config/requirements.txt # 在run的时候启动uwsgi # CMD uwsgi --ini uwsgi_conf.ini # 暴露端口 EXPOSE 8000
1.2制作镜像并生成容器
制作镜像
docker image build -t djangoproject:1.0 .
简单生成容器,这里先用run指令来运行,后面再出一篇docker-compose的。
docker run -itd --name djangoproject -p 3210:8000 djangoproject:1.0
1.3效果


2.ubuntu镜像
ubuntu镜像(500+M)比Python(1G)镜像占内存更小。
2.1Dockerfile
# 基于 ubuntu:20.04 FROM ubuntu:20.04 #复制该文件夹至镜像 RUN mkdir /APP ADD . /APP # 设置工作目录 WORKDIR /APP # 更新软件源为阿里云 RUN cat /APP/config/sources.list > /etc/apt/sources.list \ # 更新软件 && apt-get -y update \ # 安装依赖 && apt-get install -y python3-dev python3-pip \ && apt-get install -y python3-setuptools \ && apt-get install -y libmysqlclient-dev \ # 安装python依赖 && pip config set global.index-url https://pypi.douban.com/simple/ \ && pip install -r /APP/config/requirements.txt #对外暴露端口 EXPOSE 8000
2.2sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
Comments NOTHING