Backup Docker data

My version of HedgeDoc is: 1.9.8

What I expected to happen:

I have a docker installation that I backup regularly. I followed this docker documentation page to save both database and app images as tar files. I know the backup procedure described in hedgedoc documentation differs from the one I performed but I expected both to work.

What actually happened:

I restored the images using docker image load -i <my_image.tar>, then ran the containers using docker run -it <container_id>. The hedgedoc app container output goes as follow :

2024-02-21T14:16:02.443Z warn: Session secret not set. Using random generated one. Please set `sessionSecret` in your config.json file. All users will be logged out.
2024-02-21T14:16:03.781Z warn: Database cannot be reached. Try 1 of 30. (SequelizeHostNotFoundError: getaddrinfo ENOTFOUND database)
2024-02-21T14:16:04.793Z warn: Database cannot be reached. Try 2 of 30. (SequelizeHostNotFoundError: getaddrinfo ENOTFOUND database)
2024-02-21T14:16:05.804Z warn: Database cannot be reached. Try 3 of 30. (SequelizeHostNotFoundError: getaddrinfo ENOTFOUND database)
(...)
2024-02-21T14:22:30.582Z error: 	Cannot reach database! Exiting.

I should mention I’m not familiar with Docker, so I wasn’t sure what I was doing. Is there a way to get my hedgedoc data back?

Hi @LifelongNovember and welcome to the HedgeDoc community!

I’m sorry, but actually have bad news for you. If you don’t have other “correct” backups as well, your data is probably lost. Let me explain this.

The concept of docker distinguishes between the application and the data that is produced by the application. In this case the database is the application and the database contents is the data.
A docker image is meant to contain an application, not it’s data. So the image of the database should only contain the database program, but not the actual database contents.
To associate data with a docker container (which is just a running instance of an image), we’re using docker volumes. A volume can either be a local directory on your disk (bind mount) or an storage-entity controlled by your docker daemon. The minimal example from the HedgeDoc docs uses the latter ones.

The command docker image save, provided by your linked page, just persists potential changes to the image itself (so the database application in this case), but not the associated volumes. Therefore, restoring with docker image load won’t bring back the contents of the volume.
Your referenced guide actually points to this by stating:

If you used a named volume to store container data, such as databases, refer to the back up, restore, or migrate data volumes page in the storage section.

Aside from this confusion, I’d like to mention that in case of a database, it’s almost always not enough to just back up the raw database files. Modern database systems tend to cache certain changes in RAM and just write them back when e.g., CPU utilization is lower, or they just write in an intermediate format to disk. Therefore, you should always consult the docs of the database regarding their backup mechanism. Most database systems have special commands for this.
That’s also the reason we’re providing the relevant command in our docs.

Regarding your backup: If you’re still on the same machine and didn’t lose the docker data, you could check with docker volume ls whether there’s something with hedgedoc in it’s name. If so, we probably could recover your data.

Kind regards,
Erik