I try to build a docker-based development box for our django app. It's running smoothly.
None of my teammembers will care about that until there is a nice IDE integration, therefore I play the new and shiny Docker Support in pycharm 5.
I followed the linked documentation and pycharm does recognise my web container and it's python interpreter.
Here's my docker-compose.yml:
web:build: .ports:- "8000:8000"volumes:- .:/srv/applinks:- database- search- cacheentrypoint: /home/deployer/web-entrypoint.shworker:build: .volumes:- .:/srv/appcommand: celery -A core worker -l infolinks:- database- search- cachedatabase:image: postgres:latestvolumes_from:- dataenvironment:- POSTGRES_USER=app_user- POSTGRES_PASSWORD=app_passworddata:image: busyboxvolumes:- /var/lib/postgresql/datasearch:image: "elasticsearch:1.7"command: "elasticsearch --http.bind_host=0.0.0.0"ports:- "9200:9200"cache:image: "redis:latest"ports:- "6379"
Unfortunately there is no docker-compose support in pycharm, that's why djangos runserver
failed upon connecting to the database. Therefore I copied the (fortunately predictable) aliases from the web container's /etc/host
:
DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2','NAME': 'app_db','USER': 'app_user','PASSWORD': 'app_password','HOST': 'docker_database_1','PORT': '5432',}
}HAYSTACK_CONNECTIONS = {'default': {'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine','URL': 'http://docker_search_1:9200/','INDEX_NAME': 'app',},
}BROKER_URL = 'redis://docker_cache_1:6379/0'
CELERY_RESULT_BACKEND = BROKER_URL
Now the database connection error is no longer there, but the output of my django server gives me this:
a6993f56e61e:python -u /opt/project/manage.py runserver docker:8001 --traceback
Performing system checks...System check identified no issues (0 silenced).
November 08, 2015 - 19:54:29
Django version 1.8.6, using settings 'core.settings.dev'
Starting development server at http://docker:8001/
Quit the server with CONTROL-C.
Error: [Errno -2] Name or service not knownProcess finished with exit code 1
No stack trace, just this.
What's strange: python -u /opt/project/manage.py
- what's this? The folder does not exist on both host and the container.
My Django Server conf:
I tried as well a pure-python conf like this:
This is like mega-confusing because it tries again to connect via the "database" link, even if I remove it from the settings at all.
What would be the next steps for debugging?
Bonus question: pyCharm does recognize the installed packages in the project settings, but it can't find it in the code, why?
UPDATE
I found out that pyCharm is starting the container for itself and is not using the existing docker container. Hence it looks like pyCharm can only work with a single container, which does not seem to be that useful at all.