docker with pycharm 5

2024/9/16 23:14:03

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:

Django server conf

I tried as well a pure-python conf like this:

Pure Python Implementation

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?

Failed import from dist-packages

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.

Answer

It turns out that pycharm 5 supports only one container per project. Basically that translates to "Docker support is useless in pyCharm 5".

Multi-container management on top of docker compose is requested here and is awaiting YOUR upvote:

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

https://en.xdnf.cn/q/72669.html

Related Q&A

How to make a simple Python REST server and client?

Im attempting to make the simplest possible REST API server and client, with both the server and client being written in Python and running on the same computer.From this tutorial:https://blog.miguelgr…

Histogram fitting with python

Ive been surfing but havent found the correct method to do the following.I have a histogram done with matplotlib:hist, bins, patches = plt.hist(distance, bins=100, normed=True)From the plot, I can see …

Subtract each row of matrix A from every row of matrix B without loops

Given two arrays, A (shape: M X C) and B (shape: N X C), is there a way to subtract each row of A from each row of B without using loops? The final output would be of shape (M N X C).Example A = np.ar…

Programmatically setting access control limits in mosquitto

I am working on an application that will use mqtt. I will be using the python library. I have been leaning towards using mosquitto but can find no way of programmatically setting access control limits …

Optimizing cartesian product between two Pandas Dataframe

I have two dataframes with the same columns:Dataframe 1:attr_1 attr_77 ... attr_8 userID John 1.2501 2.4196 ... 1.7610 Charles 0.0000 1.0618 ... 1.4813 Genarit…

Tensorflow: open a PIL.Image?

I have a script that obscures part of an image and runs it through a prediction net to see which parts of the image most strongly influence the tag prediction. To do this, I open a local image with PIL…

Django: Saving to DB from form example

It seems I had difficulty finding a good source/tutorial about saving data to the DB from a form. And as it progresses, I am slowly getting lost. I am new to Django, and please guide me. I am getting e…

eval(input()) in python 2to3

From the Python 2to3 doc:input:Converts input(prompt) to eval(input(prompt))I am currently trying to learn Python 3 after a few years working with Python 2. Can anybody please explain why the tool inse…

Post XML file using Python

Im new to Python and in need of some help. My aim is to send some XML with a post request to a URL, which is going to trigger a SMS being sent. I have a small XML document that I want to post to the UR…

Python TypeError: __init__() got multiple values for argument master

Trying to build a GUI in Python at the moment, and Im stuck at this part in particular. Every time I try to run my code it just throws the error TypeError: __init__() got multiple values for argument m…