FROM python:3 ENV PYTHONUNBUFFERED 1 RUN mkdir /code WORKDIR /code ADD requirements.txt /code/ RUN pip install -r requirements.txt ADD . /code/ VOLUME /code
Wie benutzt man django-admin startproject newproject? von außerhalb des Containers (dh von der Docker-Machine-Befehlszeile) und dann das Projekt in den Container kopieren?
Wenn ich nun das Projekt im Container starte, startet der Server und ich kann mein Projekt am richtigen Port sehen. Wenn ich jedoch das Projekt außerhalb des Containers (aber im selben Verzeichnis lokal) beginne, werden der Web- und der Nginx-Container nicht richtig gestartet.
Ich verwende eine Docker-Maschine unter Windows 10 Version 1709.
Die Ausgabe des Webcontainer-Starts ist unten gefolgt von der Ausgabe des Servers auf Anforderung.
Prost Traceback (most recent call last): web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection web_1 | self.connect() web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect web_1 | self.connection = self.get_new_connection(conn_params) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection web_1 | connection = Database.connect(**conn_params) web_1 | File "/usr/local/lib/python3.6/site-packages/psycopg2/init.py", line 130, in connect web_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) web_1 | psycopg2.OperationalError: could not connect to server: Connection refused web_1 | Is the server running on host "db" (172.19.0.2) and accepting web_1 | TCP/IP connections on port 5432? web_1 | web_1 | web_1 | The above exception was the direct cause of the following exception: web_1 | web_1 | Traceback (most recent call last): web_1 | File "manage.py", line 22, in web_1 | execute_from_command_line(sys.argv) web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/management/init.py", line 364, in execute_from_command_line web_1 | utility.execute() web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/management/init.py", line 356, in execute web_1 | self.fetch_command(subcommand).run_from_argv(self.argv) web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv web_1 | self.execute(*args, **cmd_options) web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute web_1 | output = self.handle(*args, **options) web_1 | File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 110, in handle web_1 | loader.check_consistent_history(connection) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 282, in check_consistent_history web_1 | applied = recorder.applied_migrations() web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations web_1 | self.ensure_schema() web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema web_1 | if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()): web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 254, in cursor web_1 | return self._cursor() web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 229, in _cursor web_1 | self.ensure_connection() web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection web_1 | self.connect() web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 94, in exit web_1 | six.reraise(dj_exc_type, dj_exc_value, traceback) web_1 | File "/usr/local/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise web_1 | raise value.with_traceback(tb) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection web_1 | self.connect() web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect web_1 | self.connection = self.get_new_connection(conn_params) web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection web_1 | connection = Database.connect(**conn_params) web_1 | File "/usr/local/lib/python3.6/site-packages/psycopg2/init.py", line 130, in connect web_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) web_1 | django.db.utils.OperationalError: could not connect to server: Connection refused web_1 | Is the server running on host "db" (172.19.0.2) and accepting web_1 | TCP/IP connections on port 5432?
Serverausgabe
NGINXDOCKERNAME | 2017/11/21 19:56:28 [error] 5#5: *1 connect() failed (113: No route to host) while connecting to upstream, client: 192.168.99.1, server: localhost, request: "GET /polls/ HTTP/1.1", upstream: "http://172.19.0.3:8000/polls/", host: "192.168.99.100:8000"