基于Docker构建Python开发环境

1. Dockerfile

dockerfile所在目录结构

shell 复制代码
FROM python:3.8
WORKDIR  /leo
RUN apt-get install -y wget
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
# ssh免密登录
COPY id_rsa.pub /leo
RUN mkdir ~/.ssh\
&& cat /leo/id_rsa.pub >> ~/.ssh/authorized_keys
RUN touch /leo/start.sh
RUN echo "service ssh restart; while [ 1 == 1 ]; do echo '123' ; sleep 100 ; done;" > /leo/start.sh
# ssh
RUN apt-get update \
&& apt-get install -y libwrap0 openssh-server\
&& echo "PermitRootLogin yes" >>  /etc/ssh/sshd_config
# git配置自动保存密码
RUN git config --global credential.helper store \
&& git config --global user.name "LeoLi"\
&& git config --global user.email  LeoLi.Li@groupm.com
ENTRYPOINT [ "bash", "/leo/start.sh"]

build

shell 复制代码
docker build -f ./DockerfilePython -t python38:1.0 .
2. docker run
复制代码
docker run -d  -p 10001:22  -p  8888:5000 -p 9000:9000 -p 7777:7777  -v C:\Users\leoli.li\DockerShare:/leo  --name=python38  leo-python38:latest

查看ssh服务是否正常启动

service ssh status

3.Vscode 免密打开项目

config

shell 复制代码
Host gme
    HostName 127.0.0.1
    Port 10001
    User root
    IdentityFile C:\Users\leoli.li\.ssh\id_rsa
git

第一次拉取代码需要输入用户名密码,后面就不需要了

相关推荐
j7~2 分钟前
【Python】(篇七)《使用Python库》 -- 详解
开发语言·后端·python·编程学习·python标准库·python第三方库·python拓展
User_芊芊君子13 分钟前
Prometheus接入Pushgateway实战:二进制与Docker部署、指标推送及远程上报
docker·容器·prometheus
databook32 分钟前
手把手带你走一遍:机器学习模型如何用FastAPI和Docker部署
python·docker·fastapi
DanCheng-studio1 小时前
计算机技术与科学毕业设计简单的方向建议
python·毕业设计·毕设
言乐61 小时前
Python排名统计折线图
开发语言·python·django·virtualenv·pygame
浩瀚地学1 小时前
deepagents学习打卡day08
经验分享·笔记·python·学习·agent
卷无止境1 小时前
便宜模型和贵模型到底差在哪儿?一份关于Claude与GPT分级体系的深度梳理
后端·python
玩美移动1 小时前
AI Skin Analysis API 技术解析:文件上传、异步任务与结果读取
java·人工智能·python
江湖有缘2 小时前
3款开源日记工具整理合集,可Docker一键部署!
docker·容器·开源
j7~2 小时前
【Python】(篇六)《基础语法(函数、列表和元组、字典、文件)》---详解
开发语言·python·文件·函数·字典·编程学习·元组与列表