Postgres is available as a docker image on dockerhub/postgres. Configuration is easily done via environment variables but they also state
Warning: the Docker specific variables will only have an effect if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup.
That makes me wonder if there is a safety risk when having a Dockerfile like this
FROM postgres COPY *.sql /docker-entrypoint-initdb.d/
and a docker-compose.yml like this
database: build: context: ./database/ dockerfile: ./Dockerfile environment: POSTGRES_PASSWORD: test123 ports: - 5432:5432 volumes: - databasevol:/var/lib/postgresql/data networks: - net volumes: databasevol: driver: local networks: net: driver: bridge
which will rebuild the current database image based on
postgres:latest which may lead to the database being initialised by version 12.4 but later being read by version 13.0. The possibility of having the DBMS identify the data directory as corrupted and purging it horrifies me.
Hence the question, is it safe to run databases in docker containers?