【问题标题】:Configure PyCharm interpreter with docker-compose inside Vagrant在 Vagrant 中使用 docker-compose 配置 PyCharm 解释器
【发布时间】:2016-03-17 11:16:31
【问题描述】:

我有一个基本的 vagrant box,里面运行着 docker 和 docker-compose。 docker-compose.yaml 有一个这样的网络服务:

web:
  restart: always
  build: .
  ports: 
    - "5000:5000"
  expose:
    - "5000"
  links:
    - postgres:postgres
  volumes:
    - .:/usr/src/app/
  env_file: .env
  command: python manage.py runserver
#below the postgres service is defined

流浪文件:

Vagrant.configure(2) do |config|

  config.vm.box = "phusion/ubuntu-14.04-amd64"

  config.vm.network "private_network", ip: "192.168.33.69"

  config.vm.synced_folder ".", "/vagrant_data"
  # provisioning

web 服务使用 Dockerfile,其内容为:FROM python:3.5.1-onbuild

我安装了 PyCharm 5.1 Professional Edition Beta 2(内部版本 145.256.43,2016 年 3 月 11 日)。我想将 pycharm 的解释器配置为运行 web 服务的解释器。
当我尝试这样做时,在“配置远程 python 解释器”对话框窗口中,我选择 Docker Compose,然后添加一个新的 Docker 服务器。在尝试添加 docker 服务器时,当我输入 vagrant 机器的 ip + 端口 2376(这是输入字段中的默认值)时,出现异常:
screenshot

有什么我遗漏的问题吗?

【问题讨论】:

    标签: vagrant pycharm docker-compose


    【解决方案1】:

    好的,我终于让它工作了。 这是我所做的:

    1. 进入虚拟机,在/etc/default 中,我打开了docker 文件。取消注释 DOCKER_OPTS 行并将其更改为:
      DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
    2. 在我的 Vagrantfile(定义运行 docker 守护进程的 VM 的文件中,我将同步文件夹更改为

      config.vm.synced_folder ".", "/vagrant", disabled: true # make sure you add this line
      config.vm.synced_folder ".", "/home/georgi/Projects/ipad", # /home/georgi.... is the full path of the project on the host machine. This lines makes sure that the path of the project on the host and on the vm are the same.
          owner: 'vagrant',
          group: 'vagrant',
          mount_options: ["dmode=777", "fmode=777"]
      config.vm.synced_folder "~/.PyCharm2016.1/system/tmp", "/home/georgi/.PyCharm2016.1/system/tmp", 
          owner: 'vagrant',
          group: 'vagrant',
          mount_options: ["dmode=777", "fmode=777"]  
      

      此时重启虚拟机。

    3. 在 PyCharm 中,我打开了项目,进入 File->Settings->Project->Project Interpreter->Add Remote。已选择 Docker-Compose。
    4. 在“服务器”部分中,按“新建”。输入API如下: tcp://192.168.33.69:2375(ip 是在 Vagrantfile 中为 vm 定义的那个。端口是在 DOCKER_OPTS 中定义的那个。)其余部分保持不变。然后按确定。
    5. 在配置中——选择docker-compose.yaml——关键部分在这里——这个文件的路径在宿主机和虚拟机应该是一样的。
    6. 服务名称 - 在我的例子中 - web

    编辑:我忘了提 - 我安装了 PyCharm 2016.1

    EDIT 2017:查看thisthis。较新版本的 Docker 似乎不接受原始答案中的技巧。

    【讨论】:

      猜你喜欢
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      • 2019-01-29
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      相关资源
      最近更新 更多