Using PyCharm docker integration with minikube


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.


Docker, pycharm and minikube installed.

Set up docker in PyCharm

My minikube docker-env

export DOCKER_HOST="tcp://"
export DOCKER_CERT_PATH="/home/kozikow/.minikube/certs"
export DOCKER_API_VERSION="1.23"

My pycharm configuration


You need to replace tcp reported by docker-env with https.

Configure remote interpreter

Now that pycharm knows how to connect to docker inside minikube, configure a python interpreter as described in .

Share the path with the VM

Problem with pycharm bindings

When using docker on localhost or within the docker-machine, pycharm configure binds paths from localhost to the docker image.

When using the minikube VM, pycharm decides to bind the path from the VM instead of localhost. I created bug about this: .

Pycharm run configurations, that allow debugging within code running in the container, rely on binding your project code to /opt/project. Currently, the only option is sharing the path between your localhost and the VM.

It needs to be configured only once for minikube VM.

Configure binding in VirtualBox

If you use different VM provider you may need different settings. I want to share all my git repos with the virtualbox VM. I store them at /home/kozikow/git_repos. Firstly, I need to configure sharing in the virtualbox GUI:


Mount paths in the VM

minikube ssh
mkdir -p /home/kozikow/git_repos
sudo chown -R docker /home/kozikow

sudo mount -t vboxsf git_repos /home/kozikow/git_repos

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:


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"
ExecStop=/usr/local/bin/minikube stop

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 , and connecting to it after kubectl run.

1 Comment

Leave a Reply to hanale10 Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s