Codementor Events

Debug Flask/FastAPI App in Docker with PyCharm

Published Sep 24, 2021Last updated Apr 11, 2022
Debug Flask/FastAPI App in Docker with PyCharm

1. Clone flask project. (Credit: Ernst Haagsman)

➜ mkdir flask
➜ cd flask
➜ git clone https://github.com/ErnstHaagsman/flask-compose.git Cloning into 'flask-compose'...
remote: Enumerating objects: 35, done.
remote: Total 35 (delta 0), reused 0 (delta 0), pack-reused 35 Receiving objects: 100% (35/35), 6.49 KiB | 3.25 MiB/s, done. Resolving deltas: 100% (7/7), done.

2. Open project in Pycharm

Screenshot 2021-09-24 at 9.29.44 AM.png

Screenshot 2021-09-24 at 9.30.26 AM.png

3. Check Prerequisites Link

4. Configuring Docker: Link

Screenshot 2021-09-24 at 9.31.51 AM.png

5. Configuring Docker Compose as a remote interpreter Link

  • Click on show All

Screenshot 2021-09-24 at 9.33.04 AM.png

  • Click on + and select Docker Compose and wait while PyCharm starts your Docker-Compose configuration to scan and index

Screenshot 2021-09-24 at 9.33.40 AM.png

  • Select Docker compose and click on OK.

Screenshot 2021-09-24 at 9.35.34 AM.png

7. Running your application under Docker-Compose Link

  • Click on edit configuration,
  • Select python Interpreter: Remote Python .... And click on Apply and ok

Screenshot 2021-09-24 at 9.36.52 AM.png

Screenshot 2021-09-24 at 9.37.20 AM.png

Before running the project Docker container status:

Screenshot 2021-09-24 at 9.38.18 AM.png

Run project by clicking on debug icon.

Screenshot 2021-09-24 at 9.39.04 AM.png

  • Put debug points and access, http://localhost:5000

Screenshot 2021-09-24 at 9.39.44 AM.png

After project is running Docker container status:

Screenshot 2021-09-24 at 9.40.05 AM.png

Let me know in comment box if you want to know how to Run flask app in Debug mode in docker over ssh session, I will post article on that as well based on users response.

Note: For FastAPI also we can perfomr same step and run app inside docker and in debug mode.

Thank you.

Discover and read more posts from Avaiya Laleet
get started
post commentsBe the first to share your opinion
John Carten
3 years ago

Thanks Laleet,
I have one question, Can I use PyCharm community edition ?

Avaiya Laleet
3 years ago

No John,
It’s Professional feature, so you can not use PyCharm community edition.

John Carten
3 years ago

Thanks.

Show more replies