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.
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 at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND