PyCharm+Docker Dev
Last updated
Was this helpful?
Last updated
Was this helpful?
The official guide above use Docker, we use Docker Compose instead.
After set interpreter, there might be some frustrating errors like
cCouldn't refresh skeletons for remote interpreter The docker-compose process terminated unexpectedly: /usr/local/bin/docker-compose -f docker-compose.yml -f .PyCharm2018.3/system/tmp/docker-compose.override.8.yml run --rm --name skeleton_generator_643129755 python Regenerate skeletons
or
can't open file '/opt/.pycharm_helpers/pycharm/django_test_manage.py' + "No such file or directory"
Found a solution:
Then you should clear all pycharm helpers from your docker containers and images:
docker ps -a | grep -i pycharm | awk '{print $1}' | xargs docker rm
docker images | grep -i pycharm | awk '{print $3}' | xargs docker rmi
Sometimes import local modules will counter "unresolved reference" error in PyCharm. usually it's because src code is not in your project root path, so need to adding source folders in settings->project structure.
PyCharm right-top corner
Add->Django Server:
Then you can enable debug mode.
PyCharm with Docker to debug is easy, but...
when we setup python interpreter, if we select Docker, then just follow official guide link at first of PyCharm+Docker Dev.
But we select Docker-Compose. here is a official guide.
When we debug, always not work. then found those articles:
PyCharm remote debug times out
Debugging container with custom entrypoint defined fails
Debugging Compose services with long-lasting entrypoint fails by timeout
if the script takes too long (e.g., wait for postgres, creating a new user, etc...), then the debugger won't properly start.
Seems like if we use entrypoint
in docker-compose.yml, and our python launch script not just takes too long, it won't stop actually. so debugger cannot start properly.
remove entrypoint in docker-compose.yml, then put it directly into Dockerfile.
services:
python:
build: ./docker-config/python
restart: always
networks:
- message_bridge-network
- external_api_crm
volumes:
- ./src:/message_bridge
# entrypoint: /home/docker-entrypoint.sh
COPY ./docker-entrypoint.sh /home/
CMD ["bash","docker-entrypoint.sh"]
debug works!!
set break point, click debug button, works.
see config: