Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

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 a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Docker Tutorials: Docker Image – Understanding Dockerfiles instructions & options

Hereโ€™s a step-by-step tutorial for Dockerfile, including explanations and examples for each major command. Dockerfile Tutorial A Dockerfile is a text file containing instructions to build a…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

Reference Rajesh Kumar Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories…

Read More

Docker Tutorials: Installation and Configurations

Docker Installation in Centos/RHEL Method -1: How to install Docker Community Edition via YUM? Step 1 – Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data…

Read More

Docker Tutorials: How to Install Docker in Ubuntu?

Install Docker Engine in Ubuntu NOTE – All commands you must run as root user or add a current user into a linux group name called “docker”…

Read More

Docker Lab, Excercise & Assignment – 7 – Docker Volume

Below is a very detailed tutorial and lab manual for learning Docker Volumes, using the Ubuntu image for practical, hands-on labs. This covers all major types of…

Read More

Docker Lab, Excercise & Assignment – 4 – Docker Networking

Hereโ€™s an in-depth, step-by-step tutorial and lab manual for Docker Networkingโ€”starting from basics, covering all core concepts, and providing a hands-on guide to every feature and command….

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