<分区>
我跑
docker-compose up
我得到:
$ docker-compose up
Starting asynchttpproxy_db_1
Starting asynchttpproxy_web_1
Attaching to asynchttpproxy_db_1, asynchttpproxy_web_1
db_1 | LOG: database system was shut down at 2017-05-01 05:11:54 UTC
db_1 | LOG: MultiXact member wraparound protections are now enabled
db_1 | LOG: database system is ready to accept connections
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | Unhandled exception in thread started by <function check_errors.
<locals>.wrapper at 0x7fae3f078e18>
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/backends/base/base.py", line 130, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/backends/base/base.py", line 119, 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_psycopg2/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 164, in connect
web_1 | conn = _connect(dsn, connection_factory=connection_factory,
async=async)
web_1 | psycopg2.OperationalError: could not connect to server: Connection
refused
web_1 | Is the server running on host "localhost" (127.0.0.1) and
accepting
web_1 | TCP/IP connections on port 5432?
web_1 | could not connect to server: Cannot assign requested address
web_1 | Is the server running on host "localhost" (::1) 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 "/usr/local/lib/python3.6/site-
packages/django/utils/autoreload.py", line 229, in wrapper
web_1 | fn(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/core/management/commands/runserver.py", line 116, in
inner_run
web_1 | self.check_migrations()
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/core/management/commands/runserver.py", line 168, in
check_migrations
web_1 | executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/migrations/executor.py", line 19, in __init__
web_1 | self.loader = MigrationLoader(self.connection)
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/migrations/loader.py", line 47, in __init__
web_1 | self.build_graph()
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/migrations/loader.py", line 182, in build_graph
web_1 | self.applied_migrations = recorder.applied_migrations()
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/migrations/recorder.py", line 59, in applied_migrations
web_1 | self.ensure_schema()
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/migrations/recorder.py", line 49, 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 162, in cursor
web_1 | cursor = self.make_debug_cursor(self._cursor())
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/backends/base/base.py", line 135, in _cursor
web_1 | self.ensure_connection()
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/backends/base/base.py", line 130, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/utils.py",
line 97, 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 658, 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 130, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.6/site-
packages/django/db/backends/base/base.py", line 119, in connect
web_1 | self.connection = self.get_new_connection(conn_params)
web_1 | File "/usr/local/lib/python3.6/site-pac
kages/django/db/backends/postgresql_psycopg2/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 164, in connect
我去/c/program files/postgresql/9.3/
我愿意
postgres -D data
我明白了
$ postgres -D data
2017-05-01 00:18:14 CDT LOG: could not bind IPv6 socket: No error
2017-05-01 00:18:14 CDT HINT: Is another postmaster already running on port
5432? If not, wait a few seconds and retry.
2017-05-01 00:18:14 CDT LOG: could not bind IPv4 socket: No error
2017-05-01 00:18:14 CDT HINT: Is another postmaster already running on port
5432? If not, wait a few seconds and retry.
2017-05-01 00:18:14 CDT WARNING: could not create listen socket for "*"
2017-05-01 00:18:14 CDT FATAL: could not create any TCP/IP sockets
我的 settings.py 中的数据库是:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'async_http_proxy2',
'USER': 'postgres',
'HOST': 'localhost',
'PORT': 5432,
}
}
我的 Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
我的docker-compose.yml
version: '2'
services:
db:
image: postgres
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
我现在不知道该怎么办。请帮忙。提前致谢。