Docker with picharm 5

I am trying to create a docker-based development box for our django application. It works smoothly.

None of my team members will take care of this until there is a nice IDE integration, so I play the new and brilliant Docker Support in pycharm 5 .

I followed the related documentation and pycharm recognizes my web container and python interpreter.

Here is my docker-compose.yml:

web: build: . ports: - "8000:8000" volumes: - .:/srv/app links: - database - search - cache entrypoint: /home/deployer/web-entrypoint.sh worker: build: . volumes: - .:/srv/app command: celery -A core worker -l info links: - database - search - cache database: image: postgres:latest volumes_from: - data environment: - POSTGRES_USER=app_user - POSTGRES_PASSWORD=app_password data: image: busybox volumes: - /var/lib/postgresql/data search: image: "elasticsearch:1.7" command: "elasticsearch --http.bind_host=0.0.0.0" ports: - "9200:9200" cache: image: "redis:latest" ports: - "6379" 

Unfortunately, pycharm does not support docker-compose support, so djangos runserver could not connect to the database. So I copied the (supposedly predictable) aliases from the /etc/host web container:

 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 no longer exists, but the output from my django server gives me the following:

 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 known Process finished with exit code 1 

No stack trace, only that.

What is strange: python -u /opt/project/manage.py - what is it? The folder does not exist on the host and in the container.

My Django Server conf:

Django server conf

I also tried clean-python, like this:

Pure Python implementation

This is like mega-confusion because it tries to connect again through the "database" link, even if I remove it from the settings at all.

What will be the next steps for debugging?

Bonus question: pyCharm recognizes installed packages in the project settings, but cannot find it in the code, why?

Failed to import from dist packages

UPDATE

I found out that pyCharm runs the container for itself and does not use the existing docker container. Therefore, it seems that pyCharm can only work with one container, which does not seem to be that useful.

+5
source share
2 answers

It turns out that pycharm 5 only supports one container for each project. This basically means docker support is useless in pyCharm 5.

Here, multi-container control is requested on top of the docker layout and waits for YOUR upvote:

https://youtrack.jetbrains.com/issue/IDEA-137765

+5
source

I have a solution. I am setting up a docker composition similar to yours (postgres, redis, solr). It is configured to use a custom DJANGO_SETTINGS_MODULE (called settings.docker) that looks for the DOCKER_IP environment variable for use in services. Everything is working fine.

Then I tried to get Pycharm to make it work with docker integration, since I am running Windows (hence the docker machine), I can only run in docker mode in a separate mode. Not very useful for the shell. But one in Pycharm (as you found out) launches another container, and the sink works fine. This way you get your django shell even on a windows / mac machine that should work in disconnected mode.

It also checks tests, launch servers, and any other management command in PyCharm, as well as debug / stop functions.

launch server configuration: launch server configuration

Interpreter: interpreter

In settings.docker we have

 DOCKER_IP = os.environ.get('DOCKER_IP', '127.0.0.1') # database DATABASES = { 'default': { 'ENGINE': 'transaction_hooks.backends.postgis', 'USER': 'postgres', 'NAME': "dbuser", 'HOST': DOCKER_IP, 'POST': 5432, 'CONN_MAX_AGE': None, }, } # redis REDIS_URL = "redis://%s:6379/1" % DOCKER_IP 

You get the idea

+1
source

Source: https://habr.com/ru/post/1235491/


All Articles