日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Pycharm SSH 容器中的python环境

發布時間:2024/9/15 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Pycharm SSH 容器中的python环境 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前提

  • Pycharm專業版提供ssh配置環境,可以在本地使用遠端的python環境,這樣就不需要重復配置環境,而且也能保證客戶端與服務器端環境一致性。

  • 物理機需要滿足多個python環境(多人開發),可以使用conda解決,但是更好的方式是通過容器化的方式來滿足不同開發者,不同依賴環境

鏡像打包

選擇基礎鏡像

  • 目前,常用的基礎鏡像可以選擇python容器鏡像?或者unbutun系統鏡像

  • 系統鏡像需要在上面安裝python環境,這樣下來會導致打包出來的鏡像比加大

  • python:3的基礎鏡像是debian系統,相比ubuntu更小,更便捷

編寫dockerfile

FROM python:3 # 阿里云加速 RUN echo "deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse \n\ deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse \n\ deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse \n\ deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse \n\ deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse \n\ deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse \n\ deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse \n\ deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse \n\ deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse \n\ deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse \n"\> /etc/apt/sources.list RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 RUN apt-get update && \apt-get remove openssh-client -y && \apt-get install openssh-server vim -y && \apt-get clean # 設置root密碼 RUN echo "root:111111" | chpasswd # 設置root可登陸 RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config RUN mkdir -p /app # 將需要的python依賴寫入到requirments中 COPY requirements.txt /app WORKDIR /app # 阿里云加速 RUN pip3 install --no-cache-dir -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com EXPOSE 22 # ssh服務 daemon方式運行 CMD /etc/init.d/ssh start -D

build

docker build -t python-env:1.0 .

掛載使用

docker run -itd -p 2222:22 -v /your/python/code/path/:/app python-env:1.0

驗證使用

docker exec -it 609ed1fbbee5 bash root@609ed1fbbee5:/app# python3 --version Python 3.8.3 root@609ed1fbbee5:/app# ps -ef |grep ssh root 1 0 0 07:49 ? 00:00:00 /bin/sh -c /etc/init.d/ssh start -D root 8 1 0 07:49 ? 00:00:00 /bin/sh /etc/init.d/ssh start -D root 17 8 0 07:49 ? 00:00:00 /usr/sbin/sshd -D root 31 18 0 07:51 ? 00:00:00 grep ssh root@609ed1fbbee5:/app#各位伙伴們好,詹帥本帥搭建了一個個人博客和小程序,匯集各種干貨和資源,也方便大家閱讀,感興趣的小伙伴請移步小程序體驗一下哦!(歡迎提建議)推薦閱讀牛逼!Python常用數據類型的基本操作(長文系列第①篇) 牛逼!Python的判斷、循環和各種表達式(長文系列第②篇)牛逼!Python函數和文件操作(長文系列第③篇)牛逼!Python錯誤、異常和模塊(長文系列第④篇)

總結

以上是生活随笔為你收集整理的Pycharm SSH 容器中的python环境的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。