【发布时间】:2021-08-10 06:22:57
【问题描述】:
我找到了一个 Django 项目,但未能通过以下方式在 Docker 容器中运行:
-
git clone https://github.com/hotdogee/django-blast.git -
$ cat requirements.txt在此文件中必须更新以下依赖项:- kombu==3.0.30
- psycopg2==2.8.6
我有以下 Dockerfile:
FROM python:2
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y postgresql-client
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
对于docker-compose.yml,我使用:
version: "3"
services:
dbik:
image: postgres
volumes:
- ./data/dbik:/var/lib/postgresql/data
- ./scripts/install-extensions.sql:/docker-entrypoint-initdb.d/install-extensions.sql
environment:
- POSTGRES_DB=django_i5k
- POSTGRES_USER=django
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- dbik
links:
- dbik
$ cat scripts/install-extensions.sql
CREATE EXTENSION hstore;
我不得不改变:
$ vim i5k/settings_prod.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': '5432',
}
}
请在我跑完后在日志下方
docker-compose build
docker-compose up
Attaching to djangoblast_dbik_1, djangoblast_db_1, djangoblast_web_1
dbik_1 |
db_1 |
dbik_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
dbik_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
dbik_1 | 2021-05-19 10:45:54.221 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2021-05-19 10:45:55.264 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2021-05-19 10:45:55.264 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
dbik_1 | 2021-05-19 10:45:54.221 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2021-05-19 10:45:55.264 UTC [1] LOG: listening on IPv6 address "::", port 5432
dbik_1 | 2021-05-19 10:45:54.221 UTC [1] LOG: listening on IPv6 address "::", port 5432
dbik_1 | 2021-05-19 10:45:54.226 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
dbik_1 | 2021-05-19 10:45:54.231 UTC [26] LOG: database system was shut down at 2021-05-19 10:45:07 UTC
db_1 | 2021-05-19 10:45:55.271 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
dbik_1 | 2021-05-19 10:45:54.237 UTC [1] LOG: database system is ready to accept connections
db_1 | 2021-05-19 10:45:55.283 UTC [26] LOG: database system was shut down at 2021-05-19 10:45:18 UTC
db_1 | 2021-05-19 10:45:55.292 UTC [1] LOG: database system is ready to accept connections
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:29: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.UserSocialAuth doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class UserSocialAuth(models.Model, DjangoUserMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:67: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Nonce doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Nonce(models.Model, DjangoNonceMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:78: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Association doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Association(models.Model, DjangoAssociationMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:91: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Code doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Code(models.Model, DjangoCodeMixin):
web_1 |
web_1 | /code/suit/admin.py:5: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
web_1 | from django.contrib.contenttypes import generic
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:29: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.UserSocialAuth doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class UserSocialAuth(models.Model, DjangoUserMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:67: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Nonce doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Nonce(models.Model, DjangoNonceMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:78: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Association doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Association(models.Model, DjangoAssociationMixin):
web_1 |
web_1 | /usr/local/lib/python2.7/site-packages/social/apps/django_app/default/models.py:91: RemovedInDjango19Warning: Model class social.apps.django_app.default.models.Code doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
web_1 | class Code(models.Model, DjangoCodeMixin):
web_1 |
web_1 | /code/suit/admin.py:5: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes.
web_1 | from django.contrib.contenttypes import generic
web_1 |
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 |
web_1 | You have unapplied migrations; your app may not work properly until they are applied.
web_1 | Run 'python manage.py migrate' to apply them.
web_1 | May 19, 2021 - 06:45:57
web_1 | Django version 1.8, using settings 'i5k.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | /code/rest_framework_swagger/urlparser.py:4: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
web_1 | from django.utils.importlib import import_module
web_1 |
web_1 | [19/May/2021 06:46:12]"GET / HTTP/1.1" 404 5610
web_1 | [19/May/2021 06:46:12]"GET /favicon.ico HTTP/1.1" 404 5643
最后,我跑了docker-compose run web python manage.py migrate。
如何找到管理员的用户名和密码?
提前谢谢你
【问题讨论】:
-
新建一个,python manage.py createsuperuser
标签: python django postgresql docker docker-compose