I have a problem with PostgreSQL script runing with docker-compose. I want to create only ONE table in PostgreSQL.
My script is:
DROP TABLE IF EXISTS person;
CREATE TABLE person
(
id INT NOT NULL,
name VARCHAR(255),
surname VARCHAR(255),
age INT,
email VARCHAR(255) UNIQUE
);
Log from drocker-compose Error message is:
postgres | Success. You can now start the database server using:
postgres |
postgres | pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres |
postgres | waiting for server to start....2022-07-11 08:39:50.970 UTC [48] LOG: starting PostgreSQL 14.4 (Debian 14.4-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres | 2022-07-11 08:39:50.978 UTC [48] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2022-07-11 08:39:51.000 UTC [49] LOG: database system was shut down at 2022-07-11 08:39:50 UTC
postgres | 2022-07-11 08:39:51.008 UTC [48] LOG: database system is ready to accept connections
postgres | done
postgres | server started
postgres | CREATE DATABASE
postgres |
postgres |
postgres | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create-table-person.sql
postgres | 2022-07-11 08:39:51.431 UTC [62] ERROR: syntax error at or near "CREATE" at character 30
postgres | 2022-07-11 08:39:51.431 UTC [62] STATEMENT: DROP TABLE IF EXISTS person
postgres | CREATE TABLE person
postgres | (
postgres | id integer NOT NULL PRIMARY KEY,
postgres | name VARCHAR(255),
postgres | surname VARCHAR(255),
postgres | age integer,
postgres | email VARCHAR(255)
postgres | );
postgres | psql:/docker-entrypoint-initdb.d/create-table-person.sql:9: ERROR: syntax error at or near "CREATE"
postgres | LINE 2: CREATE TABLE person
postgres | ^
postgres exited with code 3
and my Dockerfile for PostgreSQL is:
FROM postgres
ENV POSTGRES_DB testdatabase1
COPY create-table-person.sql /docker-entrypoint-initdb.d/