From: Justin Clift <justin@postgresql.org>
To: Bernd Graf <gbernd@gmx.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Filled Postgres server as Docker image
Date: Sat, 06 Jan 2024 18:36:59 +1000
Message-ID: <de56923a1e2410f1215aed427184fedb@postgresql.org> (raw)
In-Reply-To: <b0a061b5-f133-41ff-822f-cd06c82b5963@gmx.de>
References: <b0a061b5-f133-41ff-822f-cd06c82b5963@gmx.de>
On 2024-01-05 20:31, Bernd Graf wrote:
<snip>
> As it is not easy to write a Docker build to achieve my goal ...
That kind of depends. If this is a test image that you don't
need to update frequently, then you can probably take the approach
of using an existing image, and extending it to have your data.
It's pretty easy to do. As an example, here's one using that
same concept:
https://github.com/sqlitebrowser/dbhub.io/blob/e1cf6d5ecd32dfcc797a95884e78d8665087eba5/docker/Docke...
That Dockerfile grabs an existing image (for Alpine Linux in
this example), then extends it by running a bunch of commands
to do stuff I need.
The resulting image then gets tagged with a useful (to me)
name "dbhub-build:latest" so I can stop and start it as needed.
For your scenario, you could instead do something like this:
FROM postgres:latest
LABEL maintainer="Bernd Graf <gbernd@gmx.de>"
# Load the PostgreSQL data
RUN createdb -U postgres somedb
RUN psql -U postgres somedb < yourdata.sql
That will create a new Docker image based upon the "latest"
Docker PostgreSQL release, and it will load a bunch of data into
it with those last two RUN steps. Of course, you might need
different commands in the RUN steps depending on how you've
got your data prepared for loading. :)
You build the image using docker like this:
docker build --tag myimage /PATH/TO/THE/ABOVE/Dockerfile
When it finishes building the image it'll tag it as "myimage:latest",
which you can then use as you need later on.
Does that make sense?
Regards and best wishes,
Justin Clift
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: justin@postgresql.org, gbernd@gmx.de
Subject: Re: Filled Postgres server as Docker image
In-Reply-To: <de56923a1e2410f1215aed427184fedb@postgresql.org>
References: <b0a061b5-f133-41ff-822f-cd06c82b5963@gmx.de> <de56923a1e2410f1215aed427184fedb@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox