6
submitted 1 year ago* (last edited 1 year ago) by grimer@lemmy.world to c/selfhosted@lemmy.world

Just curious if there is an easy way to back up my docker-compose.yaml and .env files. I have the following directory structure for my containers:

-docker
  -<name of container>
    -.env
    -docker-compose.yml

I'd like to copy those two files for each container folder but no other subfolders that may also be in the container folder (config, data, etc). I've been trying to get my restic backups to do it but I just can't figure it out.

Is there a better way? I'd like to have backups in case my entire server dies.

UPDATE: Thank you all for the advice, I'm giving git a try and so far so good!

you are viewing a single comment's thread
view the rest of the comments
[-] grimer@lemmy.world 1 points 1 year ago

That is an option I've been thinking about but I've never used it, I'm not a dev. Maybe I'll look at it more seriously since it does sound like what would work best, I'd really apprecieate the versioning. Thanks!

[-] shadybraden@programming.dev 3 points 1 year ago

Definitely worth a shot.

One thing I do to prevent stuff from getting into a public git repo is:

  • In the git repo, make a file called .gitignore then add the line .env to it. Then git will ignore any file named .env
  • edit compose files from a computer that is separate from the one that gets secrets. I have my desktop setup to push to github. Then I make a change, then simply run `git pull on my server to download the changes.
  • make the .env only viewable by root (you'll have to use sudo nano) by running sudo chmod 600 .env && sudo chown root:root .env
this post was submitted on 30 Mar 2025
6 points (75.0% liked)

Selfhosted

62043 readers
1234 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

Detailed Rules Post

  1. Be civil.

  2. No spam.

  3. Posts are to be related to self-hosting.

  4. Don't duplicate the full text of your blog or readme if you're providing a link.

  5. Submission headline should match the article title.

  6. No trolling.

  7. Promotion posts require active participation, with an account that is at least 30 days old. F/LOSS without a paywall has exceptions, with requirements. See the rules link for details. Tags [CBH] or [AIP] are required, see the links in Rule 8 for details.

  8. AI-related discussions and AI-involved promotional posts have additional requirements for tagging, as noted in Rule 7 and the AI & Promotional Post Expanded Rules post, and find example disclosures here.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 3 years ago
MODERATORS