Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
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.

set static ip adresses for docker containers

gbzret4dgbzret4d Member
edited October 2024 in Help

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?

  • gbzret4dgbzret4d Member
    edited October 2024

    @Levi said:
    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

  • @gbzret4d said:

    @Levi said:
    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.

  • plumbergplumberg Veteran, Megathread Squad
    edited October 2024

    Why not growth service or hostname instead if ip address? Running low on ipv4 on 172:::/8 ?

    Thanked by 1tentor
  • @gbzret4d said:
    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.

    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.

    Thanked by 1gbzret4d
  • loayloay Member
    edited October 2024
    docker run -d --net network_name --ip  172.0.0.5 
    

    https://docs.docker.com/engine/network/#ip-address-and-hostname

  • gbzret4dgbzret4d Member
    edited October 2024

    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

  • 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

  • @Levi said:

    @gbzret4d said:

    @Levi said:
    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.

    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.

  • nszervernszerver Member
    edited October 2024

    @gbzret4d said:
    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.

    `

    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.

  • @nszerver said:

    @gbzret4d said:
    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.

    `

    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

    `

    ipv4 needs to be replaced with the static ipv4 adress?

  • @gbzret4d said:

    @nszerver said:

    @gbzret4d said:
    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.

    `

    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

    `

    ipv4 needs to be replaced with the static ipv4 adress?

    yes, I have a static public IP address

Sign In or Register to comment.