【发布时间】:2020-03-10 19:59:16
【问题描述】:
我输入了“docker-compose up”。它执行但在这行输出之后挂起:
app_1 | Applying sessions.0001_initial... OK
我尝试修剪容器并重新运行,但总是卡在这里。 这是我的 docker-compose.yml:
version: "3"
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command: >
sh -c "python3 manage.py wait_for_db &&
python3 manage.py migrate &&
python3 manage.py runserver 0.0.0.0:8000"
environment:
- DB_HOST=db
- DB_NAME=app
- DB_USER=postgres
- DB_PASS=supersecretpassword
depends_on:
- db
db:
image: postgres:10-alpine
environment:
- POSTGRES_DB=app
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=supersecretpassword
这是我的 Dockerfile:
FROM python:3.7-alpine
MAINTAINER Josh Doyle
ENV PYTHONBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache postgresql-client
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev
RUN pip install -r /requirements.txt
RUN apk del .tmp-build-deps
RUN mkdir /app
WORKDIR /app
COPY ./app /app
RUN adduser -D user
USER user
这是整个控制台输出:
recipe-app-api on master [⇡!?] on ???? v19.03.5 () via ???? 3.8.1 took 7s
➜ docker-compose up
recipe-app-api_db_1 is up-to-date
Creating recipe-app-api_app_1 ... done
Attaching to recipe-app-api_db_1, recipe-app-api_app_1
db_1 | The files belonging to this database system will be owned by user "postgres".
db_1 | This user must also own the server process.
db_1 |
db_1 | The database cluster will be initialized with locale "en_US.utf8".
db_1 | The default database encoding has accordingly been set to "UTF8".
db_1 | The default text search configuration will be set to "english".
db_1 |
db_1 | Data page checksums are disabled.
db_1 |
db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1 | creating subdirectories ... ok
db_1 | selecting default max_connections ... 100
db_1 | selecting default shared_buffers ... 128MB
db_1 | selecting default timezone ... UTC
db_1 | selecting dynamic shared memory implementation ... posix
db_1 | creating configuration files ... ok
db_1 | running bootstrap script ... ok
db_1 | sh: locale: not found
db_1 | 2020-03-10 17:20:52.053 UTC [29] WARNING: no usable system locales were found
db_1 | performing post-bootstrap initialization ... ok
db_1 | syncing data to disk ... ok
db_1 |
db_1 | WARNING: enabling "trust" authentication for local connections
db_1 | You can change this by editing pg_hba.conf or using the option -A, or
db_1 | --auth-local and --auth-host, the next time you run initdb.
db_1 |
db_1 | Success. You can now start the database server using:
db_1 |
db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1 |
db_1 | waiting for server to start....2020-03-10 17:20:53.324 UTC [34] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-03-10 17:20:53.342 UTC [35] LOG: database system was shut down at 2020-03-10 17:20:52 UTC
db_1 | 2020-03-10 17:20:53.349 UTC [34] LOG: database system is ready to accept connections
db_1 | done
db_1 | server started
db_1 | CREATE DATABASE
db_1 |
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1 |
db_1 | waiting for server to shut down....2020-03-10 17:20:53.908 UTC [34] LOG: received fast shutdown request
db_1 | 2020-03-10 17:20:53.912 UTC [34] LOG: aborting any active transactions
db_1 | 2020-03-10 17:20:53.914 UTC [34] LOG: worker process: logical replication launcher (PID 41) exited with exit code 1
db_1 | 2020-03-10 17:20:53.915 UTC [36] LOG: shutting down
db_1 | 2020-03-10 17:20:53.937 UTC [34] LOG: database system is shut down
db_1 | done
db_1 | server stopped
db_1 |
db_1 | PostgreSQL init process complete; ready for start up.
db_1 |
db_1 | 2020-03-10 17:20:54.028 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-03-10 17:20:54.028 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-03-10 17:20:54.033 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-03-10 17:20:54.055 UTC [45] LOG: database system was shut down at 2020-03-10 17:20:53 UTC
db_1 | 2020-03-10 17:20:54.059 UTC [1] LOG: database system is ready to accept connections
app_1 | Waiting for database...
app_1 | Database available.
app_1 | Operations to perform:
app_1 | Apply all migrations: admin, auth, contenttypes, core, sessions
app_1 | Running migrations:
app_1 | Applying contenttypes.0001_initial... OK
app_1 | Applying contenttypes.0002_remove_content_type_name... OK
app_1 | Applying auth.0001_initial... OK
app_1 | Applying auth.0002_alter_permission_name_max_length... OK
app_1 | Applying auth.0003_alter_user_email_max_length... OK
app_1 | Applying auth.0004_alter_user_username_opts... OK
app_1 | Applying auth.0005_alter_user_last_login_null... OK
app_1 | Applying auth.0006_require_contenttypes_0002... OK
app_1 | Applying auth.0007_alter_validators_add_error_messages... OK
app_1 | Applying auth.0008_alter_user_username_max_length... OK
app_1 | Applying auth.0009_alter_user_last_name_max_length... OK
app_1 | Applying core.0001_initial... OK
app_1 | Applying admin.0001_initial... OK
app_1 | Applying admin.0002_logentry_remove_auto_add... OK
app_1 | Applying admin.0003_logentry_add_action_flag_choices... OK
app_1 | Applying sessions.0001_initial... OK
如果我再次运行 docker-compose up 而不进行修剪,那么我会在输出“没有要应用的迁移”之后挂起。 我对此进行了很多研究,但没有找到答案。感谢您提供的帮助。
谢谢。
【问题讨论】:
-
嗨。您必须提供 Dockerfile 和 docker-compose.yml 文件才能更清楚
-
谢谢。更新了原帖。对不起。 S/O 和 docker 新手。
-
@JoshDoyle 你的主机操作系统是什么?你检查它没有资源问题吗? (更多 CPU/RAM)
-
我使用的是 macOS Mojave 10.14.6。
标签: django postgresql docker