How i get container to different IP address?

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.

1 Like

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.

2 Likes

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

1 Like