创建镜像
docker build -t python_dev:dev .
运行容器
docker run -d -it --name dev -p 7022:22 -p 8000:8000 python_dev:dev bash
Dockerfile
FROM ubuntu:20.04
MAINTAINER jon
ENV TZ "Asia/Shanghai"
# 拷贝项目文件
COPY . /opt/test_django_swagger
# 更换源
RUN mv /etc/apt/sources.list /etc/apt/sources.list.old
COPY ./sources.list /etc/apt/sources.list
# RUN在build 镜像时执行的命令
RUN apt update && apt install python3.8 python3-pip -y &&\
pip3 install -U pip &&\
cd /opt/test_django_swagger &&\
pip3 install -r requirements.txt &&\
DEBIAN_FRONTEND="noninteractive" apt-get install -y openssh-server &&\
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
# WORKDIR 工作的目录 容器启动时执行的命令会在该目录下执行
WORKDIR /opt/test_django_swagger/
# CMD在运行容器时执行的命令
CMD ["etc/init.d/ssh", "start"]
# 暴露端口
EXPOSE 22 8000
sources.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-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed 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
requirements.txt
drf-yasg
Django==2.2.4
网友评论