Workflow for Python with Docker + IDE for non-web

2019-03-31 13:47发布

I am currently trying to insert Docker in my Python development workflow of non-web applications.

What are the current best practices in Python development using Docker and an IDE? I need the possibility to isolate my environments with Docker and debug my code.

On the web I found many articles about the use of Docker to deploy your code:

  • Production deployments: how to build Docker images ready to spin with your application already packaged inside
  • Development environments that mirror production: extension of the above, where you can use a container to fully QA the current status of a project before deploying to production while developing

I found a lot less about an actual development workflow, apart from some tips on how to use containers with shared volumes mapped to the directories on the host while developing web applications. This approach does not apply to non-web applications and it has some issues where a simple reload (with a LiveReload-like mechanism) is not enough so you need to restart your container(s).

The closest writing I could find is this "Eight Docker Development Patterns" blog post, but it does not consider an IDE (like PyCharm I am using now).

Maybe this question is the result of the 3-4 hours (and counting) spent configuring PyCharm to use a remote Python interpreter running in a Docker container. I expected a much better integration between the two.

1条回答
做个烂人
2楼-- · 2019-03-31 14:20

Actually, I believe that using the Docker interpreter in PyCharm is the way to go. Which version of PyCharm do you have? If you have the 2016 version, it should be set up within seconds. You just have to make sure your docker machine is running and you must have your image built that you would like to use with your project. PyCharm will find the Docker machine in the "add remote interpreter" dialog automatically. Then select your image and you're all set up.

You can run your code as usual then, almost without any delay.

Here's what worked for me: https://www.jetbrains.com/help/pycharm/2016.1/configuring-remote-interpreters-via-docker.html

And make sure to update PyCharm, that solved some issues I had.

查看更多
登录 后发表回答