栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Docker创建 django虚拟环境

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker创建 django虚拟环境

1 Dockerfile 内容如下:

FROM python:3.7

ENV PYTHonUNBUFFERED 1

WORKDIR /root

COPY pip.conf /root/.pip/pip.conf
COPY . /root

EXPOSE 22 8000

RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && 
    mv /root/sources.list /etc/apt/sources.list && 
    apt-get clean && apt-get update && 
    apt install openssh-server -y && 
    apt install vim -y && 
    mkdir /var/run/sshd && 
    sed -i '35i PermitRootLogin yes' /etc/ssh/sshd_config && 
    # SSH login fix. Otherwise user is kicked off after login
    sed 's@sessions*requireds*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd && 
    echo "export VISIBLE=now" >> /etc/profile && 
    echo "root:123456" |chpasswd && 
    pip install -r requirements.txt && 
    cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

CMD ["/usr/sbin/sshd", "-D"]
  1. 创建images
    sudo docker build -t py_env:full_v1 .
  2. 创建容器
    sudo docker run -itd -v ~/yzm/docker/opsnew/ops_backup:/root/opsnew -p 8022:22 -p 8080:8000 --name=dj_ops --restart=always py_env:full_v1

pip.conf内容

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

sources.list内容

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free

4 . vs code 远程连接,如果出现连接不上,可能是保存的秘钥错误,删除重新自动获取即可

文件位置

  1. 重新安装扩展,设置python运行环境即可
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/313970.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号