Docker Community Forums

Share and learn in the Docker community.

Running command on container that exits immediately


(Sjumbiot78) #1

Hi

I’m trying to use rclone as a backup solution by rclone’ing every night…

I have a docker container that works if I run it with bin/bash. then I can use commandline to do rclone…
but if I don’t run the container to bin/bash then it exits immediately.

Is there a way to either:

a: start the existing container and then run my command (preferably in a single line)
or
b: create a container, run my command, delete the container (this would be in a script I guess :slight_smile: )

can someone guide me to achieve the above so I can run it every night :slight_smile:


(David Maze) #2

I think the setup you’re looking for is one where whatever data the container has that needs to be backed up or persisted is stored in the host filesystem (using the docker run -v option). You should try to plan things so that, if you lose your entire /var/lib/docker directory (maybe you moved hosts, things break sometimes too) you don’t actually lose any data.

That having been said: why doesn’t it work to run whatever your backup command is in the “command” position of the docker run command (e.g., where you do or don’t put bash)?


(Sjumbiot78) #3

hadn’t actually tried that… don’t really know why… but was focused on how to do it on a schedule…

here’s my command I just issued and which is running…

docker run -ti -v /media/6a874986-7a03-4fe8-b9fb-3fbfc6cc3e95/docker/dockers/rclone:/files -v /media/6a874986-7a03-4fe8-b9fb-3fbfc6cc3e95/media/:/media valentine/rclone:latest rclone --config /files/rclone.conf copy /media/source/media/ gdrive:media

now… i’m ran this in putty and it’s giving me output in console but I don’t really need that in the future…

So the container will run it’s course and exit… right?

would I just start it on a schedule then…from now on?

docker start ?