pycharm远程调试docker容器内程序
文章链接: https://blog.csdn.net/hanchaobiao/article/details/84069299
参考链接: https://blog.csdn.net/github_33934628/article/details/80919646 https://blog.csdn.net/Wendy019900107/article/details/81985837
一、首先假设你已启动了一个docker容器,并在启动时将容器的22端口映射到宿主机的10022端口
启动示例:
docker run -d --name django_api -p 8000:80 -p 10022:22 -p 5000:5000 --link mysql_host:mymysql --link redis_host:myredis -v $PWD:/home/docker/code/app/:Z python3/django/ngnix
启动后使用xshell远程连接宿主机的10022端口是无法连接成功的,此时我们需要进入docker容器内部进行一些操作:
二、进行容器内部修改
彩蛋:文章最后我会讲解如何修改Dockerfile 使其在建立时就允许ssh远程登陆
docker exec -it 容器名 /bin/bash
1、修改root用户密码
passwd
2、首先检查容器内部是否以安装 openssh-server与openssh-client 若没安装执行一下命令安装
apt-get install openssh-server
apt-get install openssh-client
3、修改SSH配置文件以下选项
vim /etc/ssh/sshd_config
# PermitRootLogin prohibit-password # 默认打开 禁止root用户使用密码登陆,需要将其注释
RSAAuthentication yes #启用 RSA 认证
PubkeyAuthentication yes #启用公钥私钥配对认证方式
PermitRootLogin yes #允许root用户使用ssh登录
4、启动sshd服务
/etc/init.d/ssh restart
5、退出容器,连接测试
ssh root@127.0.0.1 -p 10022
输入密码成功进入容器内部即配置成功
6、如若需要将修改后的容器重新保存为镜像,则可进行相应处理,本文直接使用修改后的镜像进行后续操作
三、使用Pycharm远程连接
1、打开配置界面
2、按照远程服务器信息配置信息:配置好后可以点击测试连接测试是否能够连接成功
点击测试连接
将本地的代码和服务器代码连接
此时便可以远程调试代码了
测试上传本地代码到服务器:
彩蛋:修改Dockerfile 建立镜像时就允许用户通过远程连接
由于我在CMD中启动了 supervisord 此时容器启动后需要手动进入容器启动sshd
/etc/init.d/ssh start
或者将启动命令放入supervisor-app.conf文件中,使其建立容器时就启动
# Copyright 2013 Thatcher Peskens
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM ubuntu:16.04
MAINTAINER Dockerfiles
# Install required packages and remove the apt packages cache when done.
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
git \
vim \
python3 \
python3-dev \
python3-setuptools \
python3-pip \
nginx \
supervisor \
openssh-server \
sqlite3 && \
pip3 install -U pip setuptools && \
rm -rf /var/lib/apt/lists/*
# 更新pip
RUN pip3 install --upgrade pip
# install uwsgi now because it takes a little while
RUN pip3 install uwsgi
RUN pip3 install meld3==1.0.0
# setup all the configfiles
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# 设置root用户密码
RUN echo root:hancb|chpasswd
# 允许root用户使用密码通过ssh登录
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
RUN sed -i 's/PermitRootLogin prohibit-password/# PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
## 启动ssh连接
RUN /etc/init.d/ssh start
COPY nginx-app.conf /home/docker/code/app/
# 将配置文件软连接过去, 注意需要写绝对路径
RUN rm -f /etc/nginx/sites-available/default
RUN ln -s /home/docker/code/app/nginx-app.conf /etc/nginx/sites-available/default
COPY supervisor-app.conf /home/docker/code/app/
RUN rm -f /etc/supervisor/conf.d/supervisor-app.conf
RUN ln -s /home/docker/code/app/supervisor-app.conf /etc/supervisor/conf.d/
RUN ln -s /home/docker/code/app/conf/supervisord.conf /etc/supervisor/conf.d/ # celery
# COPY requirements.txt and RUN pip install BEFORE adding the rest of your code, this will cause Docker's caching mechanism
# to prevent re-installing (all your) dependencies when you made a change a line or two in your app.
COPY requirements.txt /home/docker/code/app/
RUN pip3 install -r /home/docker/code/app/requirements.txt
# 设置默认python版本为python3
# RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 3
# RUN update-alternatives --install /usr/bin/python python /usr/bin/python2 2
# add (the rest of) our code
COPY uwsgi.ini /home/docker/code/app/
COPY uwsgi_params /home/docker/code/app/
# install django, normally you would remove this step because your project would already
# be installed in the code/app/ directory
# RUN django-admin.py startproject website /home/docker/code/app/
EXPOSE 80
CMD ["supervisord", "-n"]
pycharm远程调试docker容器内程序的更多相关文章
- Docker容器内连接宿主机即CentOS的Mysql服务器
docker的宿主机是虚拟机下的CentOS 博主最近遇到一种情况,从服务器拷贝了一份数据库在宿主机Mysql服务器上,想要用本地的数据库测试自己的代码正确性,但是项目程序都是靠docker一键部署的 ...
- Ansible 开发调试 之【pycharm远程调试】
介绍 PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成.单元测试.版本 ...
- 使用Python控制1602液晶屏实时显示时间(附PyCharm远程调试)
前言 原创文章,转载引用务必注明链接.水平有限,如有疏漏,欢迎指正. 本文介绍一下UP板的GPIO资源使用,以及一个使用Python演示一个简单的demo. 本文使用Markdown写成,为获得更好的 ...
- Flume+Kafka收集Docker容器内分布式日志应用实践
1 背景和问题 随着云计算.PaaS平台的普及,虚拟化.容器化等技术的应用,例如Docker等技术,越来越多的服务会部署在云端.通常,我们需要需要获取日志,来进行监控.分析.预测.统计等工作,但是云端 ...
- 记录一次docker容器内修改my.cnf配置文件max_allowed_packet参数的过程
1. 问题背景 在一次新版本功能开发完毕,配合测试的过程中,测试反馈某个XxlJob定时任务一直执行失败,在分析了日志之后,找到了报错的原因: Packet for query is too larg ...
- Jenkins(Docker容器内)使用宿主机的docker命令
1.Jenkins镜像 Docker容器内的Jenkins使用容器外宿主机的Docker(即DooD,还有另外的情况就是DioD),google一下有几种说法,但是都没试成功(试过一种就是修改宿主机/ ...
- [pycharm]远程调试服务器项目
Pycharm远程调试服务器项目 准备工作 创建一个临时项目,用pycharm打开项目 mkdir xxx 准备一台远程服务器,尝试连接服务器 ssh worker@ip 同步项目到pycharm 配 ...
- pycharm远程调试配置
目录: 安装pycharm 配置pycharm远程调试 使用测试 一.安装pycharm(略) 二.配置pycharm远程调试 1.菜单--->Tools--->Deployment--- ...
- centos:解决docker容器内挂载目录无权限 ls: cannot open directory .: Permission denied
docker运行一个容器后,将主机中当前目录下的文件夹挂载到容器的文件夹后 进入到docker容器内对应的挂载目录中,运行命令ls后提示: ls: cannot open directory .: P ...
随机推荐
- laravel 预加载特定的列
/**订单列表 0 已删除 1执行中 2 已过期 * * @param Request $request * * @return \Illuminate\Contracts\View\Factory| ...
- 财务CLOUD成本核算
1.关账 仓库账关账 2.应收应付是否已审核 生成财务应收应付 3.存货账关账 4.1采购存货核算 4.2零成本维护 4.3成本中心设置 4.4成本项目设置 4.5费用项目设置 4.6成本项目匹配方 ...
- Linux(Ubuntu)使用日记------markdown文件与pdf,doc,docx文件的相互转化(pandoc使用)
安装: sudo apt-get install pandoc 使用: man pandoc 查看帮助文档 直接转换,命令如下: pandoc -f markdown -t docx ./test ...
- pointer-events: none
如果为某个元素样式设置了“pointer-events: none ”,事件.连接.悬浮样式都没有了 如果为a标签设置了“pointer-events: none ”,点击a标签,不会跳转到链接地址, ...
- Codeforces1153F Serval and Bonus Problem 【组合数】
题目分析: 我们思考正好被k个区间覆盖的情况,那么当前这个子段是不是把所有的点分成了两个部分,那么在两个部分之间相互连k条线,再对于剩下的分别连线就很好了?这个东西不难用组合数写出来. 然后我们要证明 ...
- 网路知识总结(session&&Cookie&&三次握手&&请求头)
1. 请说明Session和Cookie的作用和区别 1) Cookie 存在前端 前端需要拿着cookie访问后端,Session在服务器上(文件,数据库,如Redis) 2) web访问Serve ...
- pjb fabu
#!/bin/bash PyPath=/opt/shell/mysql LocaName=`pwd` bagname=`basename $LocaName` sleep 1s ConfList=`p ...
- adb bat 执行滑动事件
chcp 65001 @echo off echo 开始滑动 set str =0 :start adb shell input swipe 100 150 100 100 choice /t 1 / ...
- CF739E Gosha is hunting DP+wqs二分
我是从其他博客里看到这题的,上面说做法是wqs二分套wqs二分?但是我好懒呀,只用了一个wqs二分,于是\(O(nlog^2n)\)→\(O(n^2logn)\) 首先我们有一个\(O(n^3)\)的 ...
- jacoco+maven 初次使用覆盖率工具
工作要搞覆盖率测试,看到公司平台上用的jacoco,就找了网上的demo自己跑了一下. 一.覆盖率测试是干什么的 http://www.open-open.com/lib/view/open14721 ...