If I want the container to get a different IP address, how can I do that?
Giving an IP address from the container settings section does not work.
If I want the container to get a different IP address, how can I do that?
Giving an IP address from the container settings section does not work.
In the default bridge mode, Docker will indeed assign a separate IP address to your container, which is different from the hostâs address.
Now, another idea you may have is, can you let the container have an IP in the same network segment as the host? If so, according to some dig, the Macvlan may be your solution.
The answer to my question is probably the âmacvlanâ method, but Iâm not a professional, so I donât have the expertise to implement or manage this method. I thought there might be a setting Im not seeing into the software that you could remind me of, but apparently there isnâtâŚ
Thank you for your interest and response.
Iâve explained it using a simple real-life scenario so itâs easy to picture what the commands do and how macvlan works: your LAN is the street, the router is the post office, your ZimaOS box is the house with a driveway (the NIC), the macvlan network is a little side-lane, and the container gets its own house number (IP). The commands just draw the street map (subnet/gateway), find the driveway (parent NIC), build the side-lane (macvlan network), and park the car at the new house (run the container with that IP). With that picture in mind, macvlan stops feeling abstractâyou can see exactly why each step is there.
Letâs set up Docker macvlan on ZimaOS step-by-step, and Iâll explain each bit like weâre giving a toy car (your container) its own house number on your street (your home network).
What macvlan does
Your home network is a street like 192.168.0.x. Your router is the post office (192.168.0.1). Your ZimaOS box already has a house number (e.g. 192.168.0.7).
macvlan lets a container get its own house number too (e.g. 192.168.0.50), so everything on the street can talk to it directly.
Important: by default, the host (ZimaOS) canât talk to the macvlan container. Everyone else on the LAN can. Iâll show an optional âhost-to-containerâ fix at the end.
Step 1) Choose your addresses
Pick numbers that match your own network. If your router is 192.168.0.1, use the example values below.
Choose a free container IP that your router isnât handing out (outside its DHCP range).
Command
# CHANGE THESE TO YOUR LAN
LAN_SUBNET=â192.168.0.0/24â # your street
LAN_GATEWAY=â192.168.0.1â # the post office (router)
CONTAINER_IP=â192.168.0.50â # the new house number for your container
What this does: we store the important numbers so we donât have to retype them.
If youâre unsure of your NIC (the cable in your ZimaOS box), this finds it:
Command
PARENT=â$(ip -4 route show default | awk â{print $5}â)â
echo âParent NIC is: $PARENTâ
What this does: it asks Linux, âwhich door do we use to reach the internet?â Thatâs your network card (often eth0 or enpâŚ).
Step 2) Create the macvlan network
Command
docker network create -d macvlan
âsubnet=â$LAN_SUBNETâ
âgateway=â$LAN_GATEWAYâ
-o parent=â$PARENTâ
lan_macvlan
What this does: it tells Docker, âmake a special street (macvlan) that plugs into my real LAN through $PARENT,â with your subnet and gateway. We name it lan_macvlan.
You can check it exists:
Command
docker network ls | grep lan_macvlan
Step 3) Start a container with a real LAN IP
Hereâs a quick test using Nginx:
Command
docker run -d --name myapp
ânetwork lan_macvlan --ip â$CONTAINER_IPâ
ârestart unless-stopped
nginx:alpine
What this does: it starts myapp on your new street and gives it the house number you chose.
Now from another device on your LAN (phone/laptop), open http://192.168.0.50 (or whatever you set) you should see Nginx.
Tip: The host itself canât reach http://192.168.0.50 yet â thatâs normal with macvlan.
It means your ZimaOS host canât talk to that container by its LAN IP (e.g. http://192.168.0.50) because macvlan purposely isolates the host from macvlan endpoints. Everyone else on your network (phones, laptops, router) can reach the container just fineâthe host is the only one âfenced off.â Think of it like you built a little side-lane with a new house number for the container; neighbors can visit it, but your main house canât step through the fence unless you add a small gate.
In Bash (and most POSIX shells), a # starts a comment. The shell ignores everything from the # to the end of that line, so nothing there is executed. Thatâs why youâll see lines like `# CHANGE THESE IF YOUR LAN IS DIFFERENT, theyâre just notes.
The first commands set three labels that mirror real life: the street your houses live on (the LAN subnet), the post office everyone uses (the gateway/router), and the new house number you want to give the container (the container IP). Next, we ask Linux which door your ZimaOS box uses to step onto the street (the parent network interface). Then we tell Docker to build a special side street (a macvlan network) that connects to your real street through that door, using the street map and post office you provided. We quickly peek to confirm that side street exists, and finally we park the toy car at its new house by starting the container on that side street and assigning it the house number you chose. From then on, every other neighbor on the street can visit that house directly; the only quirk is the host itself doesnât knock on that door by default, which is normal for macvlan.
Honestly, Iâve lost count of how many times Iâve broken my server and learned from the mistakes. But with ZimaOS 1.4.4, the new Factory Reset puts everything back to clean defaults, no fiddling or chasing weird tweaks. Iâm excited to see what the future brings.
The subnet and gateway should have â
It should be --Network and --restart
Ultimately I ended up doing it in a single line, and hard coded the ip information, and the interface of eth0 because it showed 2 eth0 and thunder⌠But I still canât get the docker I want to use it to use an IP on the network. From cmd line I had a weird error about couldnât find the online image. So it wasnât using what I had already installed. I couldnât figure out how to make the one installed use an assigned IP on start up, and I spent too many hours today trying to get macvlan with a real network ip to work.
Is there a way to set macvlan to allow for dhcp ip assignment? Anyway I can configure it in the app settings to pull a dhcp IP address?
I created a new vlan on my network that allows for devices to use 192.168.10.0/24 Right now I have dhcp off for that subnet but can easily turn it on. Itâs going to be dedicated to docker and vmâs on my network.
Also helpful advice, if you cut and post this from a windows box. You need to fix all the " double quotes and the single â to the right thing as windows messes that up.
could be a feature request ;-).. i could use a way to add more ipâs for my docker some times