Skip to content

Nuface Blog

隨意隨手記 Casual Notes

Menu
  • Home
  • About
  • Services
  • Blog
  • Contact
  • Privacy Policy
  • Login
Menu

Docker Network Create

Posted on 2025-10-302025-10-30 by Rico

When creating a Docker network, you can specify a custom subnet and gateway using the docker network create command with the --subnet and --gateway parameters.


🧩 Example Command

docker network create \
--driver=bridge \
--subnet=172.24.0.0/16 \
--gateway=172.24.0.1 \
mail-network

🔍 Explanation

ParameterDescription
--driver=bridgeSpecifies the network driver. The default is bridge. While optional, it’s good practice to include it explicitly.
--subnet=172.24.0.0/16Defines the IP subnet for the custom Docker network.
--gateway=172.24.0.1Sets the gateway address for the network.
mail-networkThe name of the Docker network being created.

✅ Verify the Network

After creation, check the network details with:

docker network inspect mail-network

You’ll see output similar to:

"IPAM": {
    "Config": [
        {
            "Subnet": "172.24.0.0/16",
            "Gateway": "172.24.0.1"
        }
    ]
}

💡 Notes

  • This setup is useful when you need containers to communicate in a predictable private IP range.
  • You can attach containers to this custom network using --network mail-network when running or creating them.
  • To list all existing Docker networks, use: docker network ls

In summary:
To create a Docker bridge network with a specific IP range and gateway, use
docker network create --subnet=<CIDR> --gateway=<IP> <network_name>.
This allows precise control over container networking in your environment.

Recent Posts

  • Enable Logrotate for Dovecot in Docker: Prevent Huge Log Files and Disk Overflow
  • 在 Docker Dovecot 中啟用 Logrotate:避免 log 爆量、磁碟被塞滿的最佳做法
  • How to Choose Suricata RuleSets on OPNsense — Practical Guide & Best Recommendations
  • OPNsense Suricata 使用指南 — 規則(RuleSets)該怎麼選?最佳實務與推薦設定
  • Proxmox VE + Proxmox Backup Server Integration & Cross-Node Restore Guide

Recent Comments

No comments to show.

Archives

  • November 2025
  • October 2025

Categories

  • AI
  • Apache
  • Cybersecurity
  • Database
  • DNS
  • Docker
  • Fail2Ban
  • FileSystem
  • Firewall
  • Linux
  • LLM
  • Mail
  • N8N
  • OpenLdap
  • OPNsense
  • PHP
  • QoS
  • Samba
  • Switch
  • Virtualization
  • VPN
  • WordPress
© 2025 Nuface Blog | Powered by Superbs Personal Blog theme