Configure PyCharm interpreter with docker-compose inside Vagrant

走远了吗. 提交于 2019-12-06 01:15:00

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

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

    Restart the VM at this point.

  3. In PyCharm, I opened the project, went to File->Settings->Project->Project Interpreter->Add Remote. Selected Docker-Compose.
  4. In the Server section, press New. Enter the API as follows: tcp://192.168.33.69:2375 (the ip is the one defined in the Vagrantfile for the vm. The port is the one defined in the DOCKER_OPTS.) Leave the rest as it is. And press Ok.
  5. In the Configuration - select the docker-compose.yaml - the key part is here - the path of this file should be the same at the host and the vm.
  6. Service name - in my case - web
  7. Voila

EDIT: I forgot to mention - I installed PyCharm 2016.1

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!