MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How to Assign a Static IP to a Docker Container in Bridge Mode

In this guide, you’ll learn how to assign a static IP address to a Docker container using a custom bridge network. This IP address will remain fixed even after your host system reboots.


โœ… Why You Need This

By default, Docker assigns dynamic IPs to containers via its bridge network. If you restart your server or container, the IP may change โ€” which breaks networking for apps relying on fixed addresses.

This tutorial helps solve that by:

  • Creating a custom bridge network
  • Assigning a fixed IP
  • Enabling auto-restart after reboot

๐Ÿงฐ Prerequisites

  • Docker installed on your Linux system (docker -v to verify)
  • Root or sudo access

๐Ÿ”ง Step 1: Create a Custom Bridge Network

The default Docker bridge does not support static IP assignment. So, first create a custom one:

docker network create \
  --driver bridge \
  --subnet 192.168.100.0/24 \
  --gateway 192.168.100.1 \
  my_custom_bridge

โœ… This creates a new Docker bridge network:

  • Subnet: 192.168.100.0/24
  • Gateway: 192.168.100.1
  • Name: my_custom_bridge

๐Ÿš€ Step 2: Run a Container with a Static IP

Now, start your container with a fixed IP and auto-restart policy:

docker run -dit \
  --name my_httpd \
  --network my_custom_bridge \
  --ip 192.168.100.10 \
  --restart unless-stopped \
  httpd
Code language: CSS (css)

โœ… This ensures:

  • 192.168.100.10 is always assigned
  • The container restarts after reboot
  • It uses your custom bridge

๐Ÿ”„ Step 3: Test Persistence After Reboot

Reboot your host system:

sudo reboot

After the reboot, run:

docker ps
docker inspect my_httpd | grep IPAddress

โœ… You should see your container up and running with the same IP.


๐Ÿ“ Additional Notes

  • Avoid IP conflicts by managing assigned IPs manually.
  • You can replace httpd with any image (e.g., nginx, mysql, your-custom-app).
  • Use docker network inspect my_custom_bridge to check connected containers.

๐Ÿง  Bonus Tip: Docker Compose Version

Create a docker-compose.yml:

version: '3.7'
services:
  web:
    image: httpd
    container_name: my_httpd
    restart: unless-stopped
    networks:
      mynet:
        ipv4_address: 192.168.100.10

networks:
  mynet:
    driver: bridge
    ipam:
      config:
        - subnet: 192.168.100.0/24
          gateway: 192.168.100.1
Code language: JavaScript (javascript)

Then run:

docker-compose up -d

โœ… Conclusion

Youโ€™ve now:

  • Created a custom Docker network
  • Assigned a static IP to a container
  • Ensured it persists across reboots

This is especially helpful for microservices, reverse proxies, and apps that require stable internal networking.


Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Docker Tutorials: Networking – Commands and Example

Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have…

Read More

Debug for Docker Container

To debug a Docker container, check its state and logs first, then its network configuration, then test connectivity from another container on the same network. This page…

Read More

Docker Training Agenda: A Hands-On Learning Path from Containers to Registries and Networking

This revised Docker training agenda turns the original outline into a practical, modern learning path for beginners and early-career DevOps engineers. It maps each module to hands-on outcomes, core commands, and common implementation decisions.

Read More

Kubernetes networking plugins/CNI plugins

1. Kubernetes CNI / Network Plugins Plugin Type AWS Azure GCP On-Prem Key Use Calico CNI + Network Policy โœ… โœ… โœ… โœ… Networking + security policies…

Read More

Using Online Tools and Calculators to Streamline DevOps Operations and Problem-Solving

DevOps teams work in a fast and noisy environment. Builds fail, alerts fire, logs grow, and deadlines do not move. In that kind of pressure, even a…

Read More

Top 10 DDI (DNS/DHCP/IPAM) Platforms: Features, Pros, Cons & Comparison

Introduction DDI (DNS, DHCP, and IP Address Management) platforms form the backbone of modern network infrastructure. Together, DNS ensures that domain names resolve correctly, DHCP automates IP…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x