Docker exec in cron

Hello!

I did a backup as described in the documentation. Everything works fine in the terminal. The backup file is created.

But as soon as I try to run this same in cron, I get the same error. And the command doesn’t work, the backup file is not created.

I have tried different options:

/usr/bin/docker exec gitlab /bin/sh -c "gitlab-backup create BACKUP=dump" &> /var/log/docker-git.log

/usr/bin/docker exec gitlab /bin/bash -c "gitlab-backup create BACKUP=dump" &> /var/log/docker-git.log

/usr/bin/docker exec gitlab /bin/sh -c "gitlab-backup create BACKUP=dump"

/usr/bin/docker exec gitlab /bin/bash -c "gitlab-backup create BACKUP=dump"

/usr/bin/docker exec -t gitlab /bin/sh -c "gitlab-backup create BACKUP=dump"

/usr/bin/docker exec -t gitlab /bin/bash -c "gitlab-backup create BACKUP=dump"

/usr/bin/docker exec -t gitlab gitlab-backup create BACKUP=dump

/usr/bin/docker exec gitlab gitlab-backup create BACKUP=dump

The error is the same:

level=debug msg="Running health check for container 97b9a7d47d2c59898f0631833f9e59b64f3606af9526598598ee2a1a73dd8fcd ..."
level=debug msg="starting exec command d8ba79d2428a702a7bf0792509630a077d8cca1cdc0c8bcfe9296cd2af1653db in container 97b9a7d47d2c59898f0631833f9e59b64f3606af9526598598ee2a1a73dd8fcd"
level=debug msg="attach: stderr: begin"
level=debug msg="attach: stdout: begin"
level=debug msg="event forwarded" ns=moby topic=/tasks/exec-added type=containerd.events.TaskExecAdded
level=debug msg=event module=libcontainerd namespace=moby topic=/tasks/exec-added
level=error msg="stream copy error: reading from a closed fifo"
level=error msg="stream copy error: reading from a closed fifo"
level=debug msg="attach: stdout: end"
level=debug msg="attach: stderr: end"
level=debug msg="attach done"
level=warning msg="Health check for container 97b9a7d47d2c59898f0631833f9e59b64f3606af9526598598ee2a1a73dd8fcd error: OCI runtime exec failed: open /run/user/0/runc-process2177002016: no such file or directory: unknown"

the /var/log/docker-git.log file is empty.

How do I fix this?
Thanks!

Docker version 20.10.17, build 100c701