Normal view

There are new articles available, click to refresh the page.
Before yesterdaytayyebi – Gordarg Blog
  • ✇tayyebi – Gordarg Blog
  • Odootayyebi
    Here are some tips for Odoo administration. To open command palette You can simply press Ctrl + K . Behind the scenes of the installation docker-compose.yml version: '3.8' services: odoo: image: odoo:15.0 container_name: odoo depends_on: - db user: "0:0" # ports: # - "8069:8069" environment: - HOST=db - USER=odoo - PASSWORD=odoo volumes: - ./data/web:/var/lib/odoo - ./data/config:/etc/odoo networks:
     

Odoo

By: tayyebi
October 9th 2024 at 12:13 am

Here are some tips for Odoo administration.

To open command palette

You can simply press Ctrl + K .

Behind the scenes of the installation

docker-compose.yml
version: '3.8'

services:
  odoo:
    image: odoo:15.0
    container_name: odoo
    depends_on:
      - db
    user: "0:0"
#    ports:
#      - "8069:8069"
    environment:
      - HOST=db
      - USER=odoo
      - PASSWORD=odoo
    volumes:
      - ./data/web:/var/lib/odoo
      - ./data/config:/etc/odoo
    networks:
      - gordarg
  db:
    image: postgres:14.1-alpine
    container_name: odoo-db
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=odoo
      - POSTGRES_PASSWORD=odoo
    volumes:
      - ./data/db:/var/lib/postgresql/data
    networks:
      - gordarg
networks:
  gordarg:
    external: true

To delete an Odoo website

When web assets are failed to load due to 404 error

This is a common issue with version 15.0 . Recreating the cached bundles can help in this case.

$> docker exec -it odoo-db psql -U odoo -d odoo
=# DELETE FROM ir_attachment WHERE name ILIKE '%assets%';

Or

$> docker exec -it odoo odoo shell -d odoo -c /etc/odoo/odoo.conf
>> env['ir.qweb'].clear_caches()
>> env['ir.qweb'].build_asset_bundle()

To upgrade Odoo

$> docker exec -it odoo odoo -d odoo -c /etc/odoo/odoo.conf -u all --xmlrpc-port=8070
  • ✇tayyebi – Gordarg Blog
  • Shrink Database & Rebuild Indexes on a databasetayyebi
    -- https://learn.microsoft.com/en-us/sql/relational-databases/databases/shrink-a-database DBCC SHRINKDATABASE (db, 10); GO -- https://stackoverflow.com/questions/32505775 use db SET QUOTED_IDENTIFIER ON SET ARITHABORT ON SET NUMERIC_ROUNDABORT OFF SET CONCAT_NULL_YIELDS_NULL ON SET ANSI_NULLS ON SET ANSI_PADDING ON SET ANSI_WARNINGS ON DECLARE @TableName varchar(255); DECLARE @IndexName varchar(255); DECLARE @SchemaName varchar(255); DECLARE @Fragmentation FLOAT; DECLARE @IndexScript varcha
     

Shrink Database & Rebuild Indexes on a database

By: tayyebi
October 1st 2024 at 1:04 pm
-- https://learn.microsoft.com/en-us/sql/relational-databases/databases/shrink-a-database

DBCC SHRINKDATABASE (db, 10);
GO

-- https://stackoverflow.com/questions/32505775

use db

SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON

DECLARE @TableName varchar(255);
DECLARE @IndexName varchar(255);
DECLARE @SchemaName varchar(255);
DECLARE @Fragmentation FLOAT;
DECLARE @IndexScript varchar(255);

SELECT 
    dbtables.[name], 
    dbindexes.[name],
    indexstats.avg_fragmentation_in_percent,
    indexstats.page_count [pages]
FROM 
    sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats
    INNER JOIN sys.tables dbtables 
        on dbtables.[object_id] = indexstats.[object_id]
    INNER JOIN sys.schemas dbschemas 
        on dbtables.[schema_id] = dbschemas.[schema_id]
    INNER JOIN sys.indexes AS dbindexes 
        ON dbindexes.[object_id] = indexstats.[object_id]
        AND indexstats.index_id = dbindexes.index_id
WHERE 
    indexstats.database_id = DB_ID()
    AND indexstats.avg_fragmentation_in_percent >= 5.0
    AND indexstats.page_count > 10
ORDER BY 
    indexstats.page_count ASC,
    indexstats.avg_fragmentation_in_percent ASC

DECLARE TableCursor CURSOR FOR  
    SELECT 
        dbtables.[name], 
        dbindexes.[name],
        dbschemas.[name],
        indexstats.avg_fragmentation_in_percent 
    FROM 
        sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats
        INNER JOIN sys.tables dbtables 
            on dbtables.[object_id] = indexstats.[object_id]
        INNER JOIN sys.schemas dbschemas 
            on dbtables.[schema_id] = dbschemas.[schema_id]
        INNER JOIN sys.indexes AS dbindexes 
            ON dbindexes.[object_id] = indexstats.[object_id]
            AND indexstats.index_id = dbindexes.index_id
    WHERE 
        indexstats.database_id = DB_ID()
        AND indexstats.avg_fragmentation_in_percent >= 5.0
        AND indexstats.page_count > 10
    ORDER BY 
        dbschemas.[name],
        dbtables.[name];

OPEN TableCursor

FETCH NEXT FROM TableCursor INTO
    @TableName,
    @IndexName,
    @SchemaName,
    @Fragmentation
 
WHILE @@FETCH_STATUS = 0 
 
BEGIN 
    IF (@Fragmentation >= 30.0)
        SET @IndexScript = 'ALTER INDEX ' + @IndexName + ' ON ' + @SchemaName + '.' + @TableName + ' REBUILD';
    ELSE IF (@Fragmentation >= 5.0)
        SET @IndexScript = 'ALTER INDEX ' + @IndexName + ' ON ' + @SchemaName + '.' + @TableName + ' REORGANIZE';
    ELSE
        SET @IndexScript = NULL;

    IF (@IndexScript IS NOT NULL)
    BEGIN
        RAISERROR (@IndexScript, 10, 0) WITH NOWAIT
        WAITFOR DELAY '00:00:01';
        EXEC(@IndexScript); 
    END

    FETCH NEXT FROM TableCursor INTO
        @TableName,
        @IndexName,
        @SchemaName,
        @Fragmentation;
 
END 
 
CLOSE TableCursor;
 
DEALLOCATE TableCursor;

  • ✇tayyebi – Gordarg Blog
  • Self-hosting a full-featured pure and lightweight mail server with Docker (Postfix & Dovecot)tayyebi
    (This article was crafted with assistance from Bing AI.) In this tutorial, we’ll walk through the process of setting up a mail server using Docker Compose and Dovecot. We’ll cover the configuration of both the Mail Transfer Agent (MTA) and the Mail Delivery Agent (MDA). [LINK TO CLONE THE REPOSITORY OR DOWNLOAD ZIP FROM GITHUB] Prerequisites Before we begin, make sure you have the following prerequisites: Docker installed on your system. Basic knowledge of Docker Compose.
     

Self-hosting a full-featured pure and lightweight mail server with Docker (Postfix & Dovecot)

By: tayyebi
July 30th 2024 at 3:11 pm

(This article was crafted with assistance from Bing AI.)

In this tutorial, we’ll walk through the process of setting up a mail server using Docker Compose and Dovecot. We’ll cover the configuration of both the Mail Transfer Agent (MTA) and the Mail Delivery Agent (MDA).

[LINK TO CLONE THE REPOSITORY OR DOWNLOAD ZIP FROM GITHUB]

Prerequisites

Before we begin, make sure you have the following prerequisites:

  1. Docker installed on your system.
  2. Basic knowledge of Docker Compose.

Concepts of mailing and containerization

Certainly! Let’s dive into each of these terms:

  1. MDA (Mail Delivery Agent): An MDA is responsible for delivering email messages to the recipient’s mailbox. It receives messages from the Mail Transfer Agent (MTA) and places them in the appropriate mailbox (e.g., using protocols like IMAP or POP3).
  2. MTA (Mail Transfer Agent): The MTA handles the routing and delivery of email messages between mail servers. It uses protocols like SMTP (Simple Mail Transfer Protocol) to transfer emails from the sender’s server to the recipient’s server.
  3. SPF (Sender Policy Framework): SPF is an email authentication method that allows domain owners to specify which servers are authorized to send emails on their behalf. SPF records list valid IP addresses for sending emails from a domain1.
  4. DKIM (DomainKeys Identified Mail): DKIM adds a digital signature to outgoing emails, allowing recipients to verify that the email came from the claimed domain. It uses public-key cryptography to sign and verify messages.
  5. DMARC (Domain-based Message Authentication Reporting and Conformance): DMARC builds upon SPF and DKIM. It instructs email servers on how to handle emails that fail SPF or DKIM checks. Domains use DMARC policies to specify actions like marking as spam or rejecting failed emails1.
  6. Postfix: Postfix is a popular open-source MTA used for routing and delivering email messages. It’s highly configurable and widely used in email server setups.
  7. Dovecot: Dovecot is an MDA and IMAP/POP3 server. It retrieves emails from the mailbox and serves them to clients (such as email clients or webmail interfaces).
  8. Docker: Docker is a containerization platform that allows you to package applications and their dependencies into lightweight containers. It simplifies deployment and ensures consistent environments.
  9. Bridge Network: In Docker, a bridge network connects containers on the same host, allowing them to communicate securely. It provides isolation and manages IP addresses for containers.
  10. SASL Authentication (Simple Authentication and Security Layer): SASL is a framework for adding authentication support to protocols. It’s commonly used for authenticating email clients with SMTP servers.
  11. Public and Private Key: Public-key cryptography uses a pair of keys: the public key (shared openly) and the private key (kept secret). These keys are used for encryption, decryption, and digital signatures.
  12. Signature and Certificate: A digital signature is created using a private key to verify the authenticity and integrity of data. Certificates (such as SSL/TLS certificates) contain public keys and additional information about the owner, issued by a Certificate Authority (CA).
  13. Docker-Compose.yml: A YAML file used to define multi-container Docker applications. It specifies services, networks, volumes, and other configurations for a Docker Compose project.
  14. Dockerfile: A text file that defines how to build a Docker image. It includes instructions for installing software, setting up configurations, and creating the image layers.

Most important commands we used during this setup

  1. telnet localhost 25: This command initiates a Telnet session to the local machine on port 25, which is typically used for SMTP (Simple Mail Transfer Protocol) communication. It allows you to interact with an email server.
  2. nano docker-compose.yml: The nano command opens the docker-compose.yml file in a text editor called Nano. This file is commonly used to define services and their configurations for Docker containers.
  3. nano dovecot.conf: Similar to the previous command, this opens the dovecot.conf file in Nano. Dovecot is an email server software, and its configuration file specifies settings related to IMAP and POP3 protocols.
  4. nano Dockerfile: Opens the Dockerfile in Nano. Dockerfiles are used to create custom Docker images by specifying instructions for building a container.
  5. docker-compose up --build: This command starts the services defined in the docker-compose.yml file and rebuilds the images if necessary.
  6. docker container exec -i: Executes a command inside a running Docker container. The -i flag allows interactive input.
  7. chmod 777 data/ -R: Changes permissions recursively for the data/ directory, giving read, write, and execute permissions to everyone.
  8. cat data/spool/mail/*: Displays the contents of all files in the data/spool/mail/ directory. These files likely contain email messages.
  9. nano main.cf: Opens the main.cf configuration file for Postfix, a popular mail transfer agent (MTA).
  10. ufw status: Checks the status of the Uncomplicated Firewall (UFW) rules.

Docker Compose

Let’s start by creating a docker-compose.yml file that defines our services:

In this configuration, we define two services: mta (Mail Transfer Agent) and mda (Mail Delivery Agent). The mta service handles SMTP traffic, while the mda service handles POP3 and IMAP traffic.

Dockerfile.mta

This Dockerfile sets up a Postfix mail server with specific configurations for sending emails through Gmail’s SMTP server. This includes additional features related to SMTP, DKIM (DomainKeys Identified Mail), and logging. Let’s break down the steps:

  1. Base Image: It starts with the official Ubuntu base image.
  2. Update and Install Packages:
    • It updates the package list and installs several packages related to Postfix, including postfix, rsyslog, mailutils, and various SASL-related libraries.
    • The apt clean command removes unnecessary files after installation.
  3. Configure master.cf:
    • Adds a configuration line to master.cf to enable the submission service for SMTP.
  4. Client Authentication:
    • Configures Postfix to use Dovecot for authentication (smtpd_sasl_type = dovecot).
    • Specifies the path for Dovecot (smtpd_sasl_path).
    • Disables TLS (smtpd_use_tls = no) and allows only authenticated users (smtpd_tls_auth_only = yes).
  5. External Relay Configuration:
    • Copies a sasl_passwd file and creates a hash map from it.
    • Sets up TLS policy for Gmail (tls_policy).
    • Manages permissions for the TLS policy file.
  6. Certificates:
    • Creates a directory for SSL certificates.
    • Copies the SSL certificate and private key.
    • Sets appropriate permissions.
  7. SASL Mechanisms:
    • Configures SASL mechanisms for SMTP authentication.
  8. Relay Configuration:
    • Sets Gmail as the relay host (relayhost = [smtp.gmail.com]:587).
    • Specifies authentication details (smtp_sasl_password_maps).
    • Sets TLS-related options.
  9. SMTP Configuration:
  10. OpenDKIM Configuration:
    • Creates directories for OpenDKIM keys.
    • Configures various options in opendkim.conf, including syslog, permissions, auto-restart, and socket settings.
    • Copies DKIM keys into the container.
    • Configures KeyTable, SigningTable, and TrustedHosts for OpenDKIM.
  11. Postfix Integration with OpenDKIM:
    • Specifies milter protocol and action (milter_protocol and milter_default_action).
    • Sets up milters for SMTP (smtpd_milters and non_smtpd_milters).
  12. Logging Configuration:
    • Configures rsyslog to capture Postfix logs (/var/log/mail.log).
  13. Email Handling Script:
    • Copies the save_email.sh script into the container and makes it executable.
  14. Virtual Email Aliases:
    • Defines virtual aliases for specific domains (@gordarg.com).
    • Maps these aliases to a local transport (virtual_transport = local).
  15. Exposed Ports:
    • Exposes SMTP ports 25 and 587.

Dockerfile.mda

This Dockerfile sets up a Dovecot mail server with specific configurations for POP3 and IMAP services.

  1. Base Image and Package Installation:
    • It starts with the official Ubuntu base image.
    • Installs dovecot-core, dovecot-pop3d, and dovecot-imapd.
  2. Working Directory and Configuration:
    • Sets the working directory to /etc/dovecot.
    • Copies the Dovecot configuration file (dovecot.conf).
  3. SSL Configuration:
    • Copies SSL certificates (dovecot.pem, dovecot.pem.private, and dh.pem).
    • Sets appropriate permissions.
    • Updates the SSL configuration in 10-ssl.conf.
  4. User Database and Permissions:
    • Copies the user database file (dovecot-users).
    • Sets permissions for the user database.
  5. Log Files:
    • Initializes log files (dovecot-info.log, dovecot.log, and dovecot-debug.log).
  6. Exposed Ports:
    • Exposes POP3 (110), IMAP (143), IMAPS (993), and an additional port (12345).
  7. User Setup:
    • Creates a user (vmail) with specified UID and GID.
    • Sets the user’s shell to /bin/bash.
  8. Start Dovecot Service:
    • Starts the Dovecot service and tails the log files.

  • ✇tayyebi – Gordarg Blog
  • Our SEO Checklisttayyebi
    Are meta canonical tags there? Are meta alternative tags there? Are meta geo tags there? Is “NAP” (Name, Address and Phone Number) available? Is the keyword which has a “Topic” equivalent in Google Trends included in the URL? For some businesses, month name can be a Topic. Is “modified date” updated after edits? Is website locale defined?
     

Our SEO Checklist

By: tayyebi
June 25th 2024 at 9:55 am
  • Are meta canonical tags there?
  • Are meta alternative tags there?
  • Are meta geo tags there?
  • Is “NAP” (Name, Address and Phone Number) available?
  • Is the keyword which has a “Topic” equivalent in Google Trends included in the URL?
    • For some businesses, month name can be a Topic.
  • Is “modified date” updated after edits?
  • Is website locale defined?
  • ✇tayyebi – Gordarg Blog
  • RAID Rescue in Linuxtayyebi
    Diagnosing Disk Health with Smartctl and Managing Storage As a system administrator or a curious Linux enthusiast, understanding the health of your storage devices is crucial. In this blog post, we’ll explore a few essential commands to diagnose disk health and manage storage resources effectively. 1. Smartctl: Assessing Disk Health What is Smartctl? Smartctl (Smartmontools) is a command-line utility that interacts with the Self-Monitoring, Analysis, and Reporting Technology (SMART)
     

RAID Rescue in Linux

By: tayyebi
February 6th 2024 at 3:38 pm

Diagnosing Disk Health with Smartctl and Managing Storage

As a system administrator or a curious Linux enthusiast, understanding the health of your storage devices is crucial. In this blog post, we’ll explore a few essential commands to diagnose disk health and manage storage resources effectively.

1. Smartctl: Assessing Disk Health

What is Smartctl?

Smartctl (Smartmontools) is a command-line utility that interacts with the Self-Monitoring, Analysis, and Reporting Technology (SMART) system in hard drives and solid-state drives. It provides valuable information about the drive’s health, performance, and potential issues.

Using Smartctl

To check the health of a specific disk (e.g., /dev/sdc), run the following command:

sudo smartctl -a /dev/sdc

Pay attention to the following key attributes:

  • Raw_Read_Error_Rate (id 1): Indicates read errors.
  • Reallocated_Sector_Ct (id 5): Reflects the number of reallocated sectors.
  • Spin_Retry_Count (id 10): Monitors spindle motor retries.
  • Reported_Uncorrect (id 187): Tracks uncorrectable errors.
  • Offline_Uncorrectable (id 198): Identifies uncorrectable errors that occurred while the drive was offline.

Remember that even if Smartctl reports a “PASSED” status, abnormal values in these attributes could indicate impending disk failure. If you encounter such issues, consider replacing the drive promptly.

2. Managing Storage with lsblk

Listing Block Devices

The lsblk command provides a concise overview of block devices (disks and partitions). To display relevant information (name, size, filesystem type, type, and mount point), use:

lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT

This output helps you identify available storage devices, their sizes, and their current mount points.

Listing UUIDs

UUIDs (Universally Unique Identifiers) are essential for identifying partitions consistently across reboots. To list UUIDs for all block devices, execute:

lsblk -o NAME,UUID

3. Checking RAID Status with /proc/mdstat

Understanding /proc/mdstat

The /proc/mdstat file provides information about software RAID (Redundant Array of Independent Disks) arrays. It shows the status of RAID devices, including any failures or resync progress.

To view the RAID status, simply run:

cat /proc/mdstat

If you encounter issues like a degraded array or failed disks, investigate further and take corrective actions.

Managing Storage and RAID

1. Zeroing Out a Disk with dd

What Does dd if=/dev/zero of=/dev/sdc bs=1M count=100 Do?

The command sudo dd if=/dev/zero of=/dev/sdc bs=1M count=100 serves a specific purpose: it writes 100 megabytes of zeros to the /dev/sdc block device. Let’s break it down:

  • if=/dev/zero: Specifies the input source as a stream of zeros.
  • of=/dev/sdc: Indicates the output destination, which is our target disk (/dev/sdc).
  • bs=1M: Sets the block size to 1 megabyte.
  • count=100: Limits the operation to writing 100 blocks (100 megabytes).

Why would we do this? Zeroing out a disk is often done before repurposing it or creating a new filesystem. It ensures that any existing data or metadata is wiped clean, preparing the disk for a fresh start.

2. Examining a Disk with mdadm

What Does sudo mdadm --examine /dev/sdc Reveal?

The mdadm utility manages software RAID arrays. When we examine /dev/sdc, we’re checking its metadata for any existing RAID information. This step is crucial before creating or adding disks to an array. It helps prevent conflicts and ensures proper configuration.

3. Creating a RAID 1 Array

Creating a RAID 1 Array with mdadm

RAID 1 (mirroring) duplicates data across multiple disks for redundancy. Let’s look at the provided commands:

  1. sudo mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/sdc missing: This command creates a RAID 1 array named /dev/md4 with two devices (/dev/sdc and a missing device). The missing device will be replaced later.
  2. sudo mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/sdc /dev/sdd: Here, we add /dev/sdd to the RAID 1 array. Now, both /dev/sdc and /dev/sdd mirror each other, providing redundancy.

Remember to adjust the commands according to your specific setup and requirements. Properly managed RAID arrays enhance data reliability and availability.

Managing RAID Arrays and Disk Mounting

1. Stopping a RAID Array

Stopping an Active RAID Array

The mdadm utility allows you to manage software RAID arrays. To stop an active array (e.g., /dev/md4), follow these steps:

  1. Unmount the Array: First, unmount the array if it’s currently mounted. Navigate out of the mounted directory using cd ~, and then unmount the device:sudo umount /mnt/md0
  2. Stop the Array: You can stop all active arrays by running:sudo mdadm --stop --scan If you want to stop a specific array (e.g., /dev/md4), pass it to the mdadm --stop command:sudo mdadm --stop /dev/md4

2. Assembling RAID Arrays

Scanning for RAID Devices

To assemble RAID arrays during system startup, use the --assemble --scan option. This command scans for existing arrays and automatically assembles them:

sudo mdadm --assemble --scan

Assembling with Specific Devices

Sometimes you need to manually assemble an array, especially when dealing with failed or missing devices. For example:

  • To assemble /dev/md0 with read-only access and /dev/sdb2 as a component device:sudo mdadm --assemble --readonly /dev/md0 /dev/sdb2
  • To forcefully assemble /dev/md4 with /dev/sdc and /dev/sdd:sudo mdadm --assemble --verbose /dev/md4 /dev/sdc /dev/sdd --force

3. Mounting the RAID Array

Mounting the Array

Once the RAID array is assembled, you can mount it to a directory (e.g., /mnt/8tb):

sudo mount /dev/md4 /mnt/8tb

Remember to adjust the commands based on your specific setup and requirements. Properly managed RAID arrays ensure data redundancy and reliability.

Managing RAID Configuration and System Files

1. Updating mdadm Configuration

Storing RAID Information

When working with RAID arrays, it’s essential to ensure that the array configuration persists across reboots. We achieve this by updating the /etc/mdadm/mdadm.conf file. Let’s break down the steps:

  1. Querying RAID Information: To manage RAID arrays effectively, we need detailed information about their structure, component devices, and current state. Use the following command to display crucial details about a RAID device (e.g., /dev/md0):sudo mdadm -D /dev/md0 The output includes the RAID level, array size, health status, UUID, and roles of component devices1.
  2. Updating mdadm.conf: To ensure automatic reassembly of RAID arrays during boot, append the array details to the mdadm.conf file:sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf This step ensures that the array configuration is preserved even after system restarts2.

2. Editing System Files

Modifying /etc/fstab

The /etc/fstab file contains information about filesystems and their mount points. Use a text editor (e.g., nano) to modify this file:

sudo nano /etc/fstab

In this file, you define which partitions or devices should be mounted at boot. Ensure that your RAID array is correctly listed here to mount it automatically.

Adjusting mdadm.conf

If you need to make manual changes to the mdadm.conf file, use:

sudo nano /etc/mdadm/mdadm.conf

Here, you can fine-tune RAID settings, specify component devices, and manage arrays.

Conclusion

By mastering these commands, you’ll be better equipped to manage RAID arrays and maintain system stability. Remember to adapt the steps to your specific setup and requirements. Happy RAID administration! 🛡🚀

  • ✇tayyebi – Gordarg Blog
  • Cleaning Up Docker Resources: A Guidetayyebi
    Introduction Docker is a powerful tool for containerization, but over time, unused resources can accumulate and consume valuable disk space. Properly managing these resources is essential for maintaining a healthy Docker environment. In this post, we’ll discuss how to clean up your Docker setup using a few essential commands. 1. docker builder prune -a The docker builder prune command removes unused build cache. When you build Docker images, intermediate layers are cached to speed up su
     

Cleaning Up Docker Resources: A Guide

By: tayyebi
February 6th 2024 at 3:23 pm

Introduction

Docker is a powerful tool for containerization, but over time, unused resources can accumulate and consume valuable disk space. Properly managing these resources is essential for maintaining a healthy Docker environment. In this post, we’ll discuss how to clean up your Docker setup using a few essential commands.

1. docker builder prune -a

The docker builder prune command removes unused build cache. When you build Docker images, intermediate layers are cached to speed up subsequent builds. However, these cached layers can accumulate and take up space. By running docker builder prune -a, you can reclaim storage by removing all unused build cache. Be cautious, though, as this action is irreversible.

2. docker system prune -a

The docker system prune command is a more comprehensive cleanup operation. It removes several types of unused resources:

  • Containers: All stopped containers are deleted.
  • Networks: Networks not used by any containers are removed.
  • Images: Both dangling (untagged) and unused images are deleted.
  • Volumes: By default, volumes are not removed to prevent accidental data loss. Use the --volumes flag to prune anonymous volumes as well.

For example:

$ docker system prune -a --volumes

3. docker volume prune

Volumes in Docker persist data even after containers are removed. The docker volume prune command removes unused volumes. If there are no containers associated with a volume, it becomes eligible for pruning. Use this command to free up space taken by orphaned volumes.

4. docker network create main

Creating a Docker network named “main” allows containers to communicate with each other. Networks are essential for connecting services within a Docker environment. This command ensures that the “main” network exists.

5. sh -c "truncate -s 0 /var/lib/docker/containers/**/*-json.log"

This command truncates log files for all Docker containers. Logs can grow significantly over time, consuming disk space. By setting the log file size to zero, you effectively clear the logs. Note that this action does not affect running containers; it only empties the log files.

Conclusion

Regularly cleaning up your Docker resources is crucial for maintaining efficiency and preventing unnecessary storage usage. Use these commands wisely, and always double-check before executing any pruning operation. Happy containerizing! 🐳

https://git.gordarg.com/tayyebi/snippets/src/branch/main/docker_prune.sh

❌
❌