python - Linking Django and Postgresql with Docker -


I have two dock containers. First of all, there is a postgrescle container, which I run using the following command.

  sudo docker run -v / home / mpmsp / project / ezdict / postgresql / data: / var / lib / postgresql / data-p 127.0.0.1:5432:5432 -name my postgrads- D postgres   

Based on this and it is working perfectly, I can connect from host to postgrescale.

The second container is a container with my demo application. The image is created using the following dockfile (on the basis):

  from Python: 3-atom exposure 8000 5432 CMD ["/ bin / bash"]   

and I run the following command to this container

  sudo docker run --link my-postgres: My-postgres -v / home / mpmsp / project / ezdict / ezbkend: / usr / src / app -name my-app -i -t my-app   

address from PS output by dock Runs that contain container links

  NAMES my-app / my However, when I'm local I go to: 8000, I see an error page from Django,  
  OperationalError at / api-auth / login / server could not connect to the following output: Connection refused Is the server running on "127.0.0.1" and accepting TCP / IP connections on port 5432? Request method: Get Request URL: http://127.0.0.1:8000/api-auth/login/ Django version: 1.6.4 Exception type: Operational error exception value: Could not connect to server: Connection refused Running on server host "127.0.0.1" and port 5432 accept TCP / IP connection? Exception Location: /usr/local/lib/python3.4/site-packages/psycopg2/__init__.py Connect, Line 164 Python Executable: / usr / local / bin / python Python Version: 3.4.1 Python Path: [' / Usr / src / app ',' /usr/local/lib/python34.zip ',' /usr/local/lib/python3.4 ',' /usr/local/lib/python3.4/plat-linux ' , '/usr/local/lib/python3.4/lib-dynload', '/root/.local/lib/python3.4/site-packages',' /usr/local/lib/python3.4/site- Packages'] server time: Ð ?? Ñ ​​?? Half, 10 Ð ?? ÐºÑ 2014 12:07:07 +0400   

Application settings

  database = {'default': {'engine': 'django.db. "" "" "" "" "" "" "" "" "Code>  

How do the linking work? Thanks in advance

Do not disclose the port to your emoticon image dockerfile As with 5432 , any Postgresql server will not run in any container made with that image:

  From Python: 3-onbuild EXPOSE 8000 CMD ["/ bin / Bash "]   

As you are then adding it to the dingo container by adding

link- my postgres: my-postgres

Your settings for the database are incorrect.

In Django Container: 127.0.0.1 means the Zenzo container which is not listening to any service on 5432 port.

Your settings.py file should be:

  statistics = {'default': {'engine': 'django.db.backends.postgresql_psycopg2', 'NAME' : 'Mydb', 'USER': 'Postgres', 'password': '', 'HOST': 'my-postgres', 'port': '5432',}}   

As you run your own Digengo Container:

Pudo Docker Run - Link Meri-Postgrad: db -v / home / mpmsp / project / ezdict / ezbk end: / usr / src / App -name my-app -i -t my-app

Then your settings.py file should be:

  Statistics = {'Default': {'Engine': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mydb', 'USER': 'Postg '', 'Password': '', 'host': 'db', 'port': '5432',}}    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -