Table of Contents
Introduction
I will write about using docker environment from minikube VM for PyCharm integration.
I wish someone would make it work as well with jedi (emacs/vim python completion daemon), but currently only PyCharm supports docker well.
Why use PyCharm docker integration?
- IDE features based on python version in the docker image, like code completion, auto-imports, library navigation or type checking.
- Debug code running inside the docker image using the PyCharm debugger.
Why use the same docker environment for PyCharm and minikube?
- You don’t need to build the same image twice for different docker environments or rely on docker push/pull.
- No need to switch between docker environments.
Prerequisites
Docker, pycharm and minikube installed.
Set up docker in PyCharm
Configure remote interpreter
Now that pycharm knows how to connect to docker inside minikube, configure a python interpreter as described in https://www.jetbrains.com/help/pycharm/2016.1/configuring-remote-interpreters-via-docker.html .
Start automatically
Starting minikube and manually mounting paths is annoying. You can do it with systemd service. Create minikube service. My /etc/systemd/system/minikube.service
looks like:
[Unit] Description=Minikube [Service] Type=oneshot TimeoutStartSec=300 User=kozikow ExecStart=/usr/local/bin/minikube start --show-libmachine-logs=true ; \ /usr/local/bin/minikube ssh "mkdir -p /home/kozikow/git_repos && sudo mount -t vboxsf git_repos /home/kozikow/git_repos" ; \ /usr/local/bin/minikube ssh "mkdir -p /home/kozikow/.config && sudo mount -t vboxsf config /home/kozikow/.config" RemainAfterExit=yes ExecStop=/usr/local/bin/minikube stop [Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo systemctl enable minikube.service sudo systemctl start minikube.service
Docker-PyCharm bugs
The integration is still new, so there are a few bugs. It’s still worth it. All bugs are in the pycharm issue tracker.
- Your images can’t have custom
ENTRYPOINT
- If you want to use docker compose inside the VM, it needs to be accessible under the same path on localhost and the VM. Sharing the repo with the VM covers this problem.
Future work
It would be nice if I could debug images launched used kubectl run
using pycharm. Images started by pycharm are not started inside kubernetes, so they can’t rely on some intra-cluster features.
At this point, the best way I found of debugging an image started by kubectl run
would be manually installing Python Debug Server on your image as described in https://www.jetbrains.com/help/pycharm/2016.1/remote-debugging.html , and connecting to it after kubectl run
.