Debug python with docker in pycharm

Why

As I really really appreciate it that we can have an isolated development environment, when I heard pycharm can debug with docker, I was more than happy. However, things are not that easy.

What I got

I tried, tried and tried. At an amazing moment, I succeeded running docker on windows through DockerToolbox. Mostly, I refer One answer to Running a Docker image in PyCharm causes ¡°Invalid volume specification¡±. (By the way, my machine and environment is exactly like the answer)

BUT suddenly I failed to repeat it.

So I changed to try it on ubuntu

Unbuntu 14.04 in Virtualbox. The default settings when adding docker as shown in fig 1 is not suitable for Ubuntu 14.

Figure 1: add_docker_linux screenshot
Figure 1: add_docker_linux screenshot

According to another SO question's answer, adding unix:///var/run/docker.sock to the API URL shows Connection successful when click Apply. But when running programs it still won't work.

And then

Problem partially solved, when we use Docker to debug our project through PyCharm, it's not attach to a running docker and/or exec the commands (by now). Instead, it starts a new Containner and runs the commands, so if we want to debug a python file, we should make sure the docker running python when open.

In other words, the Dockerfile better with the last sentence:

1
CMD ["python3"]

And in Linux (Ubuntu) when this assured, all things are OK. And now I can debug with alpine-python

TODO

After succeeding in Linux, I go back and try in windows, it's surely a bug of Pycharm and hope can be solved in a later version.

And what's more, what I really want is more than this, I hope as below:

1
2
3
4
5
6
7
8
9

+------------------------------+
| | +------------------+ +-------------------+
| | <----------------+ | | |
| Docker/rkt/others | | Desktop UI XXXXXX Happy ME |
| +----------------> | | | |
| | +------------------+ +-------------------+
+------------------------------+
Some remote servers

In other words, no applications on PC/Desktop, no more reinstall systems, no different configurations, no more configurations problems! But with full control over what we use.

I will review related techs in the future, and this is another weekend I spent play with docker and all the configurations and DIT NOTHING WORTHFUL. Well, that's typical me. -.-