我有 Dockerfile:
FROM postgres
ENV POSTGRES_USER root
ENV POSTGRES_PASSWORD root
ENV POSTGRES_DB world
COPY world.sql /docker-entrypoint-initdb.d/
我運行docker build -t postgres,然后我創建容器,但它沒有在 PG 中創建資料庫。有誰有想法嗎?
世界.sql:
CREATE TABLE city (
id integer NOT NULL,
name text NOT NULL,
countrycode character(3) NOT NULL,
district text NOT NULL,
population integer NOT NULL
);
CREATE TABLE country (
code character(3) NOT NULL,
name text NOT NULL,
continent text NOT NULL,
region text NOT NULL,
surfacearea real NOT NULL,
indepyear smallint,
population integer NOT NULL,
lifeexpectancy real,
gnp numeric(10,2),
gnpold numeric(10,2),
localname text NOT NULL,
governmentform text NOT NULL,
headofstate text,
capital integer,
code2 character(2) NOT NULL,
CONSTRAINT country_continent_check CHECK ((((((((continent = 'Asia'::text) OR (continent = 'Europe'::text)) OR (continent = 'North America'::text)) OR (continent = 'Africa'::text)) OR (continent = 'Oceania'::text)) OR (continent = 'Antarctica'::text)) OR (continent = 'South America'::text)))
);
CREATE TABLE countrylanguage (
countrycode character(3) NOT NULL,
"language" text NOT NULL,
isofficial boolean NOT NULL,
percentage real NOT NULL
);
uj5u.com熱心網友回復:
你能提供容器日志嗎?
我運行了您的解決方案,但它適用于我的情況
資料庫已成功創建
docker run -d --name my-postgresdb-container -p 5432:5432 postgres
docker logs <CONTAINER ID>
uj5u.com熱心網友回復:
語法問題
ENV POSTGRES_USER=root
ENV POSTGRES_PASSWORD=root
ENV POSTGRES_DB=world
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/421336.html
標籤:
下一篇:如何構建Docker鏡像?
