【发布时间】:2020-01-13 11:20:17
【问题描述】:
我有一个问题。我对 docker 很陌生,所以我想做的是创建一个 docker-compose 文件,在 compose 命令上也将创建数据库。问题是它不会像我很好地问它那样创建数据库。所以我的 docker-compose 看起来像:
version: '3'
services:
db:
image: postgres:latest
restart: always
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: 'postgres'
volumes:
- database_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
volumes:
database_data:
driver: local
当我在日志中启动 docker-compose up 时,我可以看到
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2020-01-13 11:14:36.259 UTC [1] LOG: starting PostgreSQL 12.1 (Debian 12.1-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-01-13 11:14:36.259 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-01-13 11:14:36.260 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-01-13 11:14:36.264 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-01-13 11:14:36.277 UTC [29] LOG: database system was shut down at 2020-01-13 11:10:57 UTC
db_1 | 2020-01-13 11:14:36.280 UTC [1] LOG: database system is ready to accept connections
在我的初始化 SQL 中只有 1 行:
CREATE DATABASE "MyDataBase";
当我列出 DB 是 Postgres 容器时,我的 DB 无处可寻。这个问题的根源可能是什么?
【问题讨论】:
标签: docker docker-compose