基于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

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

相关推荐
用户83580861879142 分钟前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L17 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅17 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅17 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L17 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅18 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L19 小时前
python的类&继承
python
Warson_L19 小时前
类型标注/type annotation
python
ThreeS21 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵1 天前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏