Running docker command in script via duplicati fails

I’m attempting to get all docker containers to stop before duplicati backups to avoid corruption. so mounting the required docker to the duplicati container and doing docker [stop/start] Radarr Sonarr Jackett Nextcloud MariaDB SWAG Deluge I see that it works as expected. But putting that in a bash script:

if [ "$DUPLICATI__OPERATIONNAME" = "Backup" ]; then
  echo "Stopping Docker Containers" >$logfile
  echo $? >>$logfile
  /usr/bin/docker stop Radarr Sonarr Jackett Nextcloud MariaDB SWAG Deluge >>$logfile
  exit 0
else
  echo "Backup Not running" >>$logfile
  exit 1
fi

I see in the log file that the echo commands worked but the docker command did nothing, no errors or anything. anyone know how to fix this?

Hello and welcome to the forum!

What exactly do you mean by this? You installed the docker binaries into the container? Also, are you mapping the docker.sock from the host to the container?

Did you run the command from within the Duplicati docker container? Make sure you aren’t testing this at the host level.

A final thought is to make sure you have the bash script identifier at the top of your script: #!/bin/bash

Yes, /var/run/docker.sock is mounted to /var/run/docker.sock and /usr/bin/docker is mounted to /usr/bin/docker and as I said running the docker commands in docker exec -it Duplicati /bin/bash within the container works.

Yes, I was 100% in the container.

sorry I failed to include the entire script before,

#!/bin/bash
logfile=“/config/docker.log”

if [ “$DUPLICATI__OPERATIONNAME” = “Backup” ]; then
echo “Stopping Docker Containers” >$logfile
echo $? >>$logfile
/usr/bin/docker stop Radarr Sonarr Jackett Nextcloud MariaDB SWAG Deluge >>$logfile
exit 0
else
echo “Backup Not running” >>$logfile
exit 1
fi

and the output of /config/docker.log is:

Stopping Docker Containers
0

the expected output is:

Stopping Docker Containers
Radarr
Sonarr
Jackett
Nextcloud
MariaDB
SWAG
Deluge

Edit: found an error in the duplicati logs:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

which means

the current user can’t access the docker engine, because you’re lacking permissions to access the unix socket to communicate with the engine.

So is there a way to get duplicati to run this as root?

That is configured at the container level. What docker image are you using? The official duplicati docker image runs duplicati as root by default. The linuxserver image does not, although you can change it to run as root (look at the PGID and PUID settings).

The two images have differences in how they map volumes so use caution if you decide to switch. Personally I use the official docker image.