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 -vto 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.10is 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
httpdwith any image (e.g.,nginx,mysql,your-custom-app). - Use
docker network inspect my_custom_bridgeto 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 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.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals