New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
set static ip adresses for docker containers
Hi,
docker containers have internal ip adresses like 172.0.0.5
If the container gets updated and recreated, docker gives the container another ip adress like 172.0.0.9.
How can i prevent the container to get a new ip adress or set the already provisioned ip adress to be static, so recreating the container wont set a new ip adress.


Comments
Did you asked this question cgpt?
No, my first place to go is LET since i trust random nerds on a very special website more than an AI
I searched for example on reddit but cant find a suitable answer
Members here has varied qualification and most of the time is just bargain hunters. Please ask tour question cgpt and get back with results. If you wish to receive actual answer without troll, ogf is a bit better in this.
Why not growth service or hostname instead if ip address? Running low on ipv4 on 172:::/8 ?
You can use a user-defined bridge network. When you create the network, specify a static IP range. Then, assign your container a fixed IP address from that range when you run it. This way, even if you recreate the container, it will retain the same IP address you assigned.
https://docs.docker.com/engine/network/#ip-address-and-hostname
I did this:
docker network create --subnet=172.0.5.0/24 --driver bridge testnetwork
i added this network to my cloudflared tunnel container and another docker container and changed the ip adress in the cloudflare tunnel settings. Now im not able to connect anymore when i open the subdomain: Bad gateway Error code 502
https://www.baeldung.com/ops/docker-assign-static-ip-container
I tried this, see my last post, but the cloudflared container cant establish a connection to another container so i cant connect through my subdomain to the docker container.
Ok i guess i found the error.
I used in cloudflare tunnel http://172.0.5.0:8111 where 8111 is the exposed port from the container but with the internal container set in cloudflared tunnel i can connect through the subdomain
Wellll technically we did our job. We watched him fix his own problem and wonder, “will I remember this when I have the same issue?”
And then squirrel chocolate oh wait I was watching Netflix.
`
ip a d st.at.ic.ip/32 dev eth0
apt update -y
apt install bridge-utils
echo "1" > /proc/sys/net/ipv4/conf/eth0/proxy_arp
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss->
ip routes
ip ro a St.at.ic.ip/32 dev docker0
arp tables
arp -s st.at.ic.ip $(cat /sys/class/net/eth0/address) -i eth0 pub
docker run -d --net network_name --ip St.at.ic.ip
`
Two solutions
1. Map the ports you need to open externally using cloudflared to the host 127.0.0.1
2. put your service and cloudflared into the same docker compose, and you can access it using the hostname without worrying about IP changes.
ipv4 needs to be replaced with the static ipv4 adress?
yes, I have a static public IP address