Postgres: Image without VOLUME

Created on 18 Jan 2016  路  5Comments  路  Source: docker-library/postgres

We have the following use case: we want to build an image with postgres AND a dataset.
This image is used by tests that, among others, update the data. By having the data inside the image, we ensure that changes remain confined in the container and that each test run in a new container can count on the same set of data.

Not having UNVOLUME or similar implies that we cannot use the current postgres official image as base image since it declares a volume.

Already mentioned in https://github.com/docker/docker/pull/8177#issuecomment-119595202

All 5 comments

@gotcha It's not how docker VOLUME actually works, as long as you don't map the volume to your host, docker engine will create a NEW folder to hold your volume files EVERY time you run the image, under /var/lib/docker/volumes, why don't you try to run postgres twice and see what happens?

@xied75 Because we want to include data in the image, we do not want docker to create a directory.

Wouldn't setting a custom value for PGDATA in your Dockerfile be a
functional workaround here?

tianon - thanks for the suggestion, that will work for my use case at least :)

Hi, I suggest another workaround - use multistage build

FROM postgres as build
FROM alpine:3.8 as postgres
COPY --from=build / /
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 5432
CMD ["postgres"]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rap2hpoutre picture rap2hpoutre  路  3Comments

andrewvo148 picture andrewvo148  路  3Comments

phanikumarp picture phanikumarp  路  3Comments

weeger picture weeger  路  4Comments

mcnesium picture mcnesium  路  3Comments