This is my docker-compose file. Is there any easy way to get a postgres extension installed? I'm trying to install pg_trgm
.
Edit: I now have two dockerfiles and an install script. It doesn't seem to be working when I run docker-compose up build
Internal server error: pq: operator does not exist: character varying % unknown
services:
db:
build:
context: .
dockerfile: db/Dockerfile
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_USER=x
- POSTGRES_PASSWORD=x
- POSTGRES_DB=x
api:
build:
context: .
args:
app_env: ${APP_ENV}
volumes:
- .:/go/src/x/y/z
ports:
- "8080:8080"
db/Dockerfile:
FROM postgres
COPY db/install-extensions.sql /docker-entrypoint-initdb.d
db/install-extensions.sql
CREATE EXTENSION IF NOT EXISTS pg_trgm;
To activate and use an extension, you must download and install the necessary files (if not delivered with the standard download) and issue the command CREATE EXTENSION <extension_name>; within an SQL client like psql . To control which extensions are already installed use: \dx within psql .
Limitations of Running PostgreSQL Database with Docker While the quick start-up and easy configuration of Docker is a boon for development and testing, it's generally not advised to run production databases in Docker. The primary reason is that Docker containers are great for running stateless applications.
Try this
FROM postgres
COPY ./install-extensions.sql /docker-entrypoint-initdb.d
and remove db from your file.
OR you can write
version: "3.1"
services:
db:
image: postgres:9.6
restart: always
environment:
POSTGRES_PASSWORD: unit
POSTGRES_USER: unit
POSTGRES_DB: unit
ports:
- 5432:5432
volumes:
- ./scripts:/docker-entrypoint-initdb.d
then
created_extension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With