Bobcares

Cleanup tasks with Docker – How quickly we perfom it

by | Oct 28, 2020

Often, customers need to perform cleanup tasks with docker to keep the Docker clean from unused containers or volumes.

At Bobcares, we often keep the Docker clean as part of our Server Management Services.

Today, let’s get into the details and see how to do cleanup tasks with Docker.

How to do cleanup tasks with Docker

Here are some tips to help you keep Docker clean.

Frequently, many Docker customers have problems due to low server space. This occurs because unwanted or unused containers take too much space to run it.

So, it gives every so often you need to clean up Docker.

The Docker cleanup tasks are not really very complicated. Also, it’s necessary to remove containers with no purpose to free up space.

Now, let us see how to do this.

 

1. Removing containers

Some reasons that we need to remove the container.

  1. Unused container:- Not every container that created continues to be used.
  2. Forget about certain lingering containers created.

 

There are two commands that can run to stop and remove all containers. However, this removes all the containers that are in use, so we can avoid such command if not want to do a wholesale removal.

Firstly, find out what containers on the system to remove.

To do this, run the command:

$ docker ps -a

The above command will list out both running and inactive containers on the system.

In addition, any container with a status of Exited is no longer running and can be safely deleted.

To delete the exited container, run the command:

$ docker rm CONTAINTER_ID

Here, CONTAINER_ID is the first few digits of the actual ID associated with the container.

Also, there are some situations to delete the running containers that no longer use.

Therefore, the below commands helps to stop the container and to remove the container.

$ docker stop CONTAINER_ID
$ docker rm CONTAINTER_ID

CONTAINER_ID – ID which associated with the container.

An alternative to removing all stopped containers is with the command:

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

 

2. Remove Docker volumes

A Docker data volume is a special directory that can bypass the Docker storage driver and communicate directly with the host file system.

Data volumes initialized when a container is created and serve as either persistent or shared data between containers.

However, the volume may remain after deleting a container. Hence called dangling volumes.

In order to  remove dangling volumes, run the following command:

$ docker volume rm $(docker volume ls -qf dangling=true)

 

Finally, run the below command to make sure the cleanup is complete:

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

 

3. Use a minimal base image

Recent official Docker images use the latest Debian as the base. The storage space can be saved by using a minimal base image (such as an official Debian image) instead of working with a larger image (such as Ubuntu)

Also, If the Debian image is still too big, we use a smallerBusyBox image.

So, we can start working with BusyBox by pulling the image, starting the container, and gaining access to the BusyBox shell with the command:

$ docker run -it --rm busybox

Once inside the BusyBox container, we can start building.

 

[Need assistance to do cleanup tasks with Docker? We’ll help you.]

 

Conclusion

In short. keeping the Docker clean helps to solve the server space issue that is especially important when Docker is running as a virtual machine. Today, we saw the important commands to remove the unused containers and how our Support Engineers do cleanup tasks with Docker.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF