Docker-Compose 在数据库创建时卡住

标签 docker docker-compose

我希望使用 docker 扩展一个网络应用程序(我是 Docker 的初学者)。我的应用程序需要 PostgreSQL。因此我决定使用 docker-compose。

docker-compose.yaml 看起来像:

version: '3.8'

services: 
    db:
        image: postgres
        command: "postgres -c listen_addresses='*'"
        environment:
            - POSTGRES_DB=CatsQMS
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=12345qwerty

    application:
        build: .
        ports:
            - "8080:8080"
        depends_on:
            - db

我还有配置我的 web 应用程序的文件 config.yaml,它看起来像这样:

database_config:
  host: db
  user: postgres
  password: 12345qwerty
  port: 5432
  database: CatsQMS

# Unimportant stuff

当我使用 docker-compose up 午餐 docker-compose 时,构建在此时卡住:

Recreating cats_queue_management_system_db_1 ... done
Recreating cats_queue_management_system_application_1 ... done
Attaching to cats_queue_management_system_db_1, cats_queue_management_system_application_1
db_1           |
db_1           | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1           |
db_1           | 2020-05-20 13:42:51.628 UTC [1] LOG:  starting PostgreSQL 12.3 (Debian 12.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           | 2020-05-20 13:42:51.628 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1           | 2020-05-20 13:42:51.628 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1           | 2020-05-20 13:42:51.635 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1           | 2020-05-20 13:42:51.660 UTC [24] LOG:  database system was shut down at 2020-05-20 13:39:45 UTC
db_1           | 2020-05-20 13:42:51.673 UTC [1] LOG:  database system is ready to accept connections

也许这是一件重要的事情,我的 Dockerfile:

FROM python:3.8

RUN mkdir /docker-entrypoint-initdb.d/

COPY ./application/sources/database/init.sql /docker-entrypoint-initdb.d/

RUN mkdir /app

WORKDIR /app

COPY . /app

RUN pip install -r requirements.txt

RUN python3 setup.py develop

ENTRYPOINT ["start_app", "-d"]

我哪里认错了?

最佳答案

您的应用程序和 PostgreSQL 数据库正在运行并且应该按预期工作。但是 Docker 在将容器运行到 db 容器后附加。

您可以使用选项 -d or --detach on docker-compose up 来避免这种情况:

The docker-compose up command aggregates the output of each container (essentially running docker-compose logs -f). When the command exits, all containers are stopped. Running docker-compose up -d starts the containers in the background and leaves them running.

所以你的命令看起来像这样:

docker-compose up -d

关于Docker-Compose 在数据库创建时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61915128/

相关文章:

docker - minikube 共享卷在一段时间后不显示文件

docker - docker上的couchbase配置

r - 将 Rstudio 与 Docker 组合使用并将环境变量传递给 rstudio 用户

php - 可以将Docker镜像设为 “built” (“compiled”)而不要求Docker吗?

ruby-on-rails - Sidekiq 在 docker-compose 上的 127.0.0.1:6379 (Errno::ECONNREFUSED) 上连接到 Redis 时出错

Docker-Compose 多行 key

docker - 如何在 Docker 容器内的 CockroachDB 中运行 SQL 脚本?

docker - 从Docker容器访问主机的文件夹

java - 带有 Spring Boot 应用程序的 Docker 卡在 RaspberryPi 上的 AnnotationConfigServletWebServerApplicationContext

docker - 无法使用 docker-compose 在 Docker 容器中运行 Traefik