Docker Community Forums

Share and learn in the Docker community.

Short term Docker ETL task


(Jasoneroi) #1

Hello,

I have built a docker node image that only needs to be run once per week for about an hour.

when the task completes, it still shows on my docker PS list, albeit “exited”.

Is there a way for a container to exit on it’s own and not appear in the docker process list? For that matter, does it matter, or take up any resources for an exited process to sit around?

Thanks in advance for your time!

–jason


(John Rofrano) #2

You can use the --rm flag which will instruct Docker to remove the container once it has exited.

docker run --rm myimage

Note that this flag is not compatible with the -d flag so the container cannot run in detached mode and must run in the foreground so that Docker is aware of when it exits. You didn’t say how you were running it once a week but this shouldn’t be a problem.

~jr


(Jasoneroi) #3

Thank you for your reply, that helps.

What are the down sides to having a bunch of exited processes that are only visible when I type “docker ps -a”? or is it that I just can’t delete the images those containers are based on until I actually run the “docker rm” command? because I can run the docker rm command periodically…

–jason


(John Rofrano) #4

The down sides are that the containers are still taking up hard drive space and as you pointed out, you cannot remove their images until the exited containers are removed. Also if they have volumes you can’t remove the volumes of exited containers either so that’s more wasted storage space unless you are naming those volumes and reusing them.

It might be a good idea to clean these both up every one in a while with:

docker rm $(docker ps -a -q -f status=exited)
docker volume prune

Note that this will also remove containers that are just stopped.

I keep a set of database containers for development stopped so that I can quickly start them when needed with docker start redis or docker start mysql and stop them just as easily when no longer needed. If you keep stopped containers around then don’t use the rm command above because it will remove those as well.

~jr