How do I run pycharm within my docker container?

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.

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

  • Docker deployment workflow of new application release without loosing database state?
  • Sandbox command execution with docker via Ajax
  • Copying file from host to container
  • How to set HOST_GID for Docker
  • Why is virtualbox running so slowly under docker?
  • Freeing unnecessary Docker image's space
  • When I create a project, click pure python and then add remote, then clicking docker I get the following result

    enter image description here

    I’m running on Mac OS X El Capitan (10.11.6) with Docker version 1.12.1 and Pycharm Pro 2016.2.3

  • Push image vs building on system itself, docker
  • Trying to build openface docker container
  • How can I make docker machine to get images from host before pulling any image for itself?
  • Ubuntu on Managed VMs using custom runtime
  • Can't use yum inside Docker container running on CentOS
  • uwsgi running in Docker can't find initializtion file
  • One Solution collect form web for “How do I run pycharm within my docker container?”

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

    If you try to add this to pycharm, you’ll get the following message:

    Only supported on Linux

    “Cannot connect: java.lang.ExceptionInInitializerError, caused by: java.lang.IllegalStateException: Only supported on Linux”

    So PyCharm really 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”.

    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.

    On my system, I have it installed via homebrew:

    brew install socat

    Now that’s installed, I can run socat with the following parameters:

    socat TCP-LISTEN:2376,reuseaddr,fork,bind= UNIX-CLIENT:/var/run/docker.sock

    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 is not.

    This socat command tells it to listen on 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.

    I can test that socat is working by running the following command:

    docker -H tcp:// ps

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

    Now, in the PyCharm window, I can put the same tcp:// in place. I should get a “Connection successful” message back:

    connection successful

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

    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 OPENSSL-LISTEN instead of the TCP-LISTEN feature. I won’t go into the details on that for this answer though.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.