How do I run pycharm within my docker container?
<p>I'm very new to docker.  I want to build my python application within a docker container. As I build the application I want to be testing / running it in Pycharm and in the container I build.  </p>

<p>How do I connect Pycharm pro to a specific container or image (either python or Anaconda)?</p>

<p>When I create a project, click pure python and then add remote, then clicking docker I get the following result</p>

<p><a href="https://i.stack.imgur.com/SVwEE.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/SVwEE.jpg" alt="enter image description here"></a></p>

<p>I'm running on Mac OS X El Capitan (10.11.6) with Docker version 1.12.1 and Pycharm Pro 2016.2.3 </p>

<p>Docker-for-mac only supports connections over the /var/run/docker.sock socket that is listening on your OSX host.</p>

<p>If you try to add this to pycharm, you'll get the following message:</p>

<p><a href="https://i.stack.imgur.com/4x5i6.png" rel="nofollow"><img src="https://i.stack.imgur.com/4x5i6.png" alt="Only supported on Linux"></a></p>

<p>"Cannot connect: java.lang.ExceptionInInitializerError, caused by: java.lang.IllegalStateException: Only supported on Linux"</p>

<p>So PyCharm <em>really</em> only wants to connect to a docker daemon over a TCP socket, and has support for the recommended TLS protection of that socket. The Certificates folder defaults to the certificate folder for the default docker-machine machine, "default".</p>

<p>It is possible to implement a workaround to expose Docker for Mac via a TCP server if you have socat installed on your OSX machine.</p>

<p>On my system, I have it installed via homebrew:</p>

<pre><code>brew install socat
</code></pre>

<p>Now that's installed, I can run socat with the following parameters:</p>

<pre><code>socat TCP-LISTEN:2376,reuseaddr,fork,bind=127.0.0.1 UNIX-CLIENT:/var/run/docker.sock
</code></pre>

<p>WARNING: this will make it possible for any process running as any user on your whole mac to access your docker-for-mac. The unix socket is protected by user permissions, while 127.0.0.1 is not.</p>

<p>This socat command tells it to listen on 127.0.0.1:2376 and pass connections on to /var/run/docker.sock. The reuseaddr and fork options allow this one command to service multiple connections instead of just the very first one.</p>

<p>I can test that socat is working by running the following command:</p>

<pre><code>docker -H tcp://127.0.0.1:2376 ps
</code></pre>

<p>If you get a successful <code>docker ps</code> response back, then you know that the socat process is doing its job.</p>

<p>Now, in the PyCharm window, I can put the same <code>tcp://127.0.0.1:2376</code> in place. I should get a "Connection successful" message back:</p>

<p><a href="https://i.stack.imgur.com/TqH0E.png" rel="nofollow"><img src="https://i.stack.imgur.com/TqH0E.png" alt="connection successful"></a></p>

<p>This workaround will require that socat command to be running any time you want to use docker from PyCharm.</p>

<p>If you wanted to do the same thing, but with TLS, you could set up certificates and make them available for both pycharm and socat, and use socat's <code>OPENSSL-LISTEN</code> instead of the <code>TCP-LISTEN</code> feature. I won't go into the details on that for this answer though.</p>

python docker anaconda