Postgres Docker container is broken after changing Postgres config Postgres Docker container is broken after changing Postgres config docker docker

Postgres Docker container is broken after changing Postgres config


Like most database images, the timescaledb image does not place your data in the container root filesystem -- it creates a volume for the data instead. By default this is an "anonymous" volume -- it has no name, and will be deleted when your delete your container.

To access the data from your timescaledb container, you first need to determine the volume id. You can get that from the output of docker container inspect:

$ docker inspect timescale --format="{{ range .Mounts }}{{.Name}}{{end}}"bee238efb681cd88c20ddedc46ca4a55a0b6b598f5c137945e8d6714fce99d4b

Here, I can see that my container named timescale was attached to the volume bee238efb681cd88c20ddedc46ca4a55a0b6b598f5c137945e8d6714fce99d4b (you would replace timescale in the above command with the name or id of your failed container). I can start up a new container using the same volume so that I can edit the configuration file(s):

$ docker run -v bee238efb681cd88c20ddedc46ca4a55a0b6b598f5c137945e8d6714fce99d4b:data --rm -it alpine sh/ # cd /data/data # lsPG_VERSION            pg_commit_ts          pg_ident.conf         pg_notify             pg_snapshots          pg_subtrans           pg_wal                postgresql.confbase                  pg_dynshmem           pg_logical            pg_replslot           pg_stat               pg_tblspc             pg_xact               postmaster.optsglobal                pg_hba.conf           pg_multixact          pg_serial             pg_stat_tmp           pg_twophase           postgresql.auto.conf

The volume is mounted on /data, and I'm free to edit files there.Once you've made the necessary changes, you can exit this temporarycontainer and then restart your failed container.


When running any sort of service for which you want your data to persist longer than the lifetime of the container, you should arrange to store your data in a named volume, which are never removed automatically.

You create a named volume by passing a name as the first argument to -v, for example:

docker run -v myimportantdata:/var/lib/postgresql/data ...

This creates a named volume named myimportantdata if it doesn't already exists, and mounts it in the container at the given path.

You should also, of course, arrange to automatically back up any data that you care about.