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/Dockerfile
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