djmaze / resticker

Run automatic restic backups via a Docker container.
https://hub.docker.com/r/mazzolino/restic/
Apache License 2.0
502 stars 68 forks source link

starting/stopping docker-compose services inside backup service #173

Open johnhelt opened 1 year ago

johnhelt commented 1 year ago

I'm trying to wrap my head around if what I'm trying is actually not possible: I have a bunch of services I want stopped. The services are defined by docker-compose files and contain binds to volumes on the local file system (outside docker).

Using the PRE_COMMANDS env variable, I can shut down the services just fine inside the backup container, after I installed docker-compose by patching the Dockerfile. The problem I have is that I cannot start them again, because all mounts point to locations on the local fs, which dont exist in docker container. Even if I could somehow solve this, I'm afraid that running docker-in-docker would lead to unexpected results if the backup container gets stopped. I don't see any good way around this rather than running my start script outside the docker container, and then, why bother using docker at all, unless it is to avoid installing restic locally?

smainz commented 1 year ago

Why do you need to shut them down? It should be enough to stop and start the containers. I do it like this:


  restic-backup:
    image: mazzolino/restic:1.7
    container_name: restic-backup
    restart: always
    environment:
      PRE_COMMANDS: |-
        docker stop nexus-app
      POST_COMMANDS_EXIT: |-
        docker start nexus-app
    ...

You only have to give the correct name for the container:

services:
  nexus:
    image: sonatype/nexus3:3.53.1
    container_name: nexus-app
    restart: always
   ...