Cleaning up exited Docker containers

book

Article ID: 222656

calendar_today

Updated On:

Products

CA Agile Central On Premise (Rally)

Issue/Introduction

When a docker container exits, it leaves behind its old files in the event that it is necessary to access the logs from that container

Over time, these containers will contribute to disk space usage.  As a maintenance task, one should periodically remove exited containers that are no longer needed.

Environment

Release : 2.0+

Component :  Docker

Resolution

Log into the services VM as ops

Run the following command:

$ sudo docker ps -a | grep Exited

 

Sample output:

561206a33341        10.17.67.114:9874/rallysoftware-ac2go-proxy:1.3.5-2.0                 "run nginx -g 'daemo…"   2 years ago         Exited (0) 2 years ago                                                      repl10aeecc4_proxy.1.awz4vtbqy5oj0j50t233kjmrd
c08032f8c04f        registry.replicated.com/library/retraced-nsq:v1.0.0-compat-20190117   "/bin/sh -c nsqd -st…"   2 years ago         Exited (255) 2 years ago      4150-4151/tcp, 4160-4161/tcp, 4170-4171/tcp   retraced_retraced-nsqd.1.kwukf10br78ygy4xoes6pq71f
fdd8e9b40e2f        registry.replicated.com/library/retraced-postgres:10.6-20190125       "docker-entrypoint.s…"   2 years ago         Exited (255) 2 years ago      5432/tcp                                      retraced_retraced-postgres.1.5p544vd1kax0vn5ec0sfmqrda
9fb9b556bfee        10.17.67.114:9874/rallysoftware-ac2go-licensing:1.1.5-2.0             "/usr/bin/launcher /…"   2 years ago         Exited (1) 2 years ago                                                      repl10aeecc4_licensing.1.gs2bn96n52rwyd9bys78hgoa9
c69b0d10a183        10.17.67.114:9874/rallysoftware-ac2go-alm:23677-2.0.1                 "run /_run/start_ser…"   2 years ago         Exited (255) 2 years ago      7001/tcp                                      repl10aeecc4_alm.1.88nc3fymyj0nh0cuvfeu9uwv7
8b45fb234dd8        alpine:3.7                                                            "cp /tmp/filename.tg…"   2 years ago         Exited (1) 2 years ago                                                      unruffled_pasteur

 

Using the container IDs from your output, as shown above, run the following command:

$ sudo docker rm 8b45fb234dd8 c69b0d10a183 9fb9b556bfee fdd8e9b40e2f c08032f8c04f 561206a33341

 

Sample output:

8b45fb234dd8
c69b0d10a183
9fb9b556bfee
fdd8e9b40e2f
c08032f8c04f
561206a33341