在Vagrant中使用docker-compose配置PyCharm解释器 [英] Configure PyCharm interpreter with docker-compose inside Vagrant

查看:65
本文介绍了在Vagrant中使用docker-compose配置PyCharm解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的无家可归者盒子,其中运行了docker和docker-compose.docker-compose.yaml具有这样的Web服务:

I have a basic vagrant box, with docker and docker-compose running in it. The docker-compose.yaml has a web service like this:

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

Vagrantfile:

Vagrantfile:

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

The web service uses a Dockerfile with content: 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服务器时,当我把无业游民的机器的IP +端口2376(这是输入字段中的默认值)时,我得到一个例外:
屏幕截图

I installed the PyCharm 5.1 Professional Edition Beta 2 (build 145.256.43, March 11, 2016). I want to configure the interpreter of pycharm as the same which runs the web service.
When I try to do so, in the "Configure remote python interpreter" dialog window, I select Docker Compose, then I add a new Docker server. When trying to add the docker server, when I put the ip of the vagrant machine + port 2376(this was the default in the input field) I get an exception:
screenshot

我缺少任何陷阱吗?

推荐答案

好吧,我终于开始使用它了.这是我所做的:

Okay I finally got it to work. Here's what I did:

  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的文件)中,我将已同步的文件夹更改为

  1. Went to the VM, and in /etc/default, I opened the docker file. Uncommented the DOCKER_OPTS line and changed it to:
    DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
  2. In my Vagrantfile (the one which defines the VM on which the docker daemon is running, I changed the synced folders to

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"]  

此时重新启动VM.

我忘了提-我安装了PyCharm 2016.1

I forgot to mention - I installed PyCharm 2016.1

EDIT 2017 :查看

EDIT 2017: Check out this or this. Newer versions of Docker seem to not accept the trick in the original answer.

这篇关于在Vagrant中使用docker-compose配置PyCharm解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆