You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Request]: A direct option to assign or configure the container's IP address #282
Currently, containers launched via the container CLI do not offer a way to define or control their IP address. This limits flexibility in several use cases, including:
Local development scenarios that rely on predictable container IPs
Inter-container communication, where fixed IPs are preferable
Integration with tools or services expecting specific network behavior
Testing network-related functionality that depends on a deterministic IP setup
While --network allows attaching to a custom network, it doesn't currently support IP address assignment or any advanced networking options.
Proposed Solution
Introduce an additional flag to container run, such as:
--ip <ip-address>
Code of Conduct
I agree to follow this project's Code of Conduct
Reacted by Morris Richman, Doug Coleman, Stephane Delval, Marco Barrios, Marco Di Pietro, Jens Mertelmeyer, wicii2120, Braulio Lobo, tuxian, Joaquin and 9 more
@danielcamargo if we go with a discrete option, --ip, we're on the path for adding options for every other network-related option. We did this for --dns because the space of options is pretty small. For network settings, al alternative would be to extend --network in a compatible way, such as:
--network name[,option_name=option_value]...
Another thing we can consider (though it'd spawn a separate issue) is how to specify fully network-isolated containers (attached to no network). Right now, not specifying network results in attaching the container to default because it's by far the common case.
This doesn't answer your question but if you just want to connect between containers, and between host and containers, then you can rely on container name.
Similar when you want a process running on host to connect to the contaiiner, you can refer to it by the container name. I was trying to run Postgres using container and was able to connect my webserver to the postgres just using the container name
Related to 1 and 2 I would like to ask how to access the container from another physical machine? My idea. Run a ubuntu server in the container. Allow users from outside to access this container.
If I publish it that way does it mean I can access the inner container from the network containing baremetal macOS as ssh user@baremetal:8000 to access the inner container?
VM’s IP to be accessible from the world,
World is not needed. Lets say I have macs A and mac B next to one another. And macA is running a ubuntu container. I would like to open Terminal (macOS) in macB and type ssh to directly reach the ubuntu container running inside macA.
The reason I want to access the inner container is that we have some crazy scientific code that works only with Linux. The users already authenticate to ldap linux. So I want anyone in the network to ssh to the linux container.
If I publish it that way does it mean I can access the inner container from the network containing baremetal macOS as
ssh user@baremetal:8000 to access the inner container?
--publish 0.0.0.0:8000:8000 would create port forwarder that listens on all of the interfaces on your system - your loopback interface, your wired Ethernet, WiFi, VPN interfaces, whatever. That's what I mean by "accessible from the world" (and why it's best practice to publish on 127.0.0.1:8000:8000 unless you have a specific need otherwise, like yours).
Of course you might be behind a VPN, which limits the size of the world that can actually route to your services. Or you might have firewall rules in place that prevent access.
If your other physical machine is on your LAN, then I think another option should be to publish on the IP address of whatever LAN adapter you're attaching with.
In any case the port publish feature is tracked by #97.
A possible approach, for anyone interested in taking this work on, is:
--network name changes to --network name[,opt_key=opt_val...].
Add a struct for a network attachment to VesselClient that has name: String and (optional) ip: String properties.
Add a parser that parses the network option string and validates the IP address if present.
Change the container configuration so that networks uses a list of the new type, instead of [String].
Update the client/server plumbing for ContainerNetworkService to add an optional address argument to allocate() to ask for the specific address if specified.
From an end-user perspective, a separate option would be better than expanding the network option. It would also maintain better compatibility with Docker's network option.
Currently, containers launched via the container CLI do not offer a way to define or control their IP address. This limits flexibility in several use cases, including:
Local development scenarios that rely on predictable container IPs
Inter-container communication, where fixed IPs are preferable
Integration with tools or services expecting specific network behavior
Testing network-related functionality that depends on a deterministic IP setup
Relying on static container IPs is an anti-pattern in cloud-native development. Fixed IPs are not preferable for inter-container communication (they're not used in compose, and they're not used to communicate between k8s pods. Names are preferable in almost all scenarios precisely because IPs can and do change all the time in the real world.
That being said, we could implement this for the relatively few cases where fixing an IP would be helpful. An implementation should handle both of these cases with a naive implementation:
Stopping and starting a container with a fixed IP. There's no guarantee that the network to which the container attaches has the same subnet as it did the last time the container was running. The container will either need to run with the original IP and be broken because its address doesn't mesh with the new subnet address, or the suffix masked requested IP will need to be joined with the prefix-masked subnet IP to create a workable container IP. This will break whatever static IP configs you have for your applications, but you'll have a container that can do networking.
Conflicts with auto-assigned IPs. If you ask for 192.168.64.5, your container may not run or restart because another container has been allocated this address. If you really wanted this to work reliably, the network would need to have an attribute for dividing the subnet into ranges for automatic IPAM and for static IPAM.
Stopping and starting a container with a fixed IP. There's no guarantee that the network to which the container attaches has the same subnet as it did the last time the container was running. The container will either need to run with the original IP and be broken because its address doesn't mesh with the new subnet address, or the suffix masked requested IP will need to be joined with the prefix-masked subnet IP to create a workable container IP. This will break whatever static IP configs you have for your applications, but you'll have a container that can do networking.
Conflicts with auto-assigned IPs. If you ask for 192.168.64.5, your container may not run or restart because another container has been allocated this address. If you really wanted this to work reliably, the network would need to have an attribute for dividing the subnet into ranges for automatic IPAM and for static IPAM.
I am currently using Docker (and hope to switch to Apple M4 hardware) as home x86 server. On that server I host different services via Docker containers.
In this case I need to have fixed IP, at least for my local PiHole DNS server (nevertheless some plain IoT devices, which utilise direct IPv4 of services like MQTT or network devices which need to use some static IP to send logs, etc).
I don't really care, if I setup it via --network or --ip (I believe it will increase compatibility with Docker).
Activity
jglogan commentedon Jul 1, 2025
@danielcamargo if we go with a discrete option,
--ip, we're on the path for adding options for every other network-related option. We did this for--dnsbecause the space of options is pretty small. For network settings, al alternative would be to extend--networkin a compatible way, such as:--network name[,option_name=option_value]...Another thing we can consider (though it'd spawn a separate issue) is how to specify fully network-isolated containers (attached to no network). Right now, not specifying network results in attaching the container to
defaultbecause it's by far the common case.nhuphucnguyen commentedon Jul 1, 2025
This doesn't answer your question but if you just want to connect between containers, and between host and containers, then you can rely on container name.
Mcrich23 commentedon Jul 9, 2025
Thanks @jglogan. This also seems very important for making technologies like Vapor usable with containers.
planetprivate commentedon Jul 10, 2025
Related to 1 and 2 I would like to ask how to access the container from another physical machine? My idea. Run a ubuntu server in the container. Allow users from outside to access this container.
example: I have something like
container run -t -i ubuntu:latest shand I install inside it sshserver.
How does one ssh to the ubuntu server running?
Is this possible? Many thanks
jglogan commentedon Jul 11, 2025
@planetprivate If you had:
would that meet your needs? That provides container access. It’s not upstream yet but I have it working in my local repo.
If what you want is for the VM’s IP to be accessible from the world, that’s not possible with the vmnet NAT bridge we’re using.
planetprivate commentedon Jul 12, 2025
@jglogan Thanks for the quick reply.
container run —publish 0.0.0.0:8000:8000 …If I publish it that way does it mean I can access the inner container from the network containing baremetal macOS as
ssh user@baremetal:8000to access the inner container?World is not needed. Lets say I have macs A and mac B next to one another. And macA is running a ubuntu container. I would like to open Terminal (macOS) in macB and type ssh to directly reach the ubuntu container running inside macA.
The reason I want to access the inner container is that we have some crazy scientific code that works only with Linux. The users already authenticate to ldap linux. So I want anyone in the network to ssh to the linux container.
Thanks!
jglogan commentedon Jul 16, 2025
@planetprivate
--publish 0.0.0.0:8000:8000would create port forwarder that listens on all of the interfaces on your system - your loopback interface, your wired Ethernet, WiFi, VPN interfaces, whatever. That's what I mean by "accessible from the world" (and why it's best practice to publish on 127.0.0.1:8000:8000 unless you have a specific need otherwise, like yours).Of course you might be behind a VPN, which limits the size of the world that can actually route to your services. Or you might have firewall rules in place that prevent access.
If your other physical machine is on your LAN, then I think another option should be to publish on the IP address of whatever LAN adapter you're attaching with.
In any case the port publish feature is tracked by #97.
jglogan commentedon Jul 31, 2025
A possible approach, for anyone interested in taking this work on, is:
--network namechanges to--network name[,opt_key=opt_val...].name: Stringand (optional)ip: Stringproperties.networksuses a list of the new type, instead of[String].marcobarrios-fi commentedon Aug 11, 2025
From an end-user perspective, a separate option would be better than expanding the network option. It would also maintain better compatibility with Docker's network option.
jglogan commentedon Jan 8, 2026
First off, regarding:
Relying on static container IPs is an anti-pattern in cloud-native development. Fixed IPs are not preferable for inter-container communication (they're not used in compose, and they're not used to communicate between k8s pods. Names are preferable in almost all scenarios precisely because IPs can and do change all the time in the real world.
That being said, we could implement this for the relatively few cases where fixing an IP would be helpful. An implementation should handle both of these cases with a naive implementation:
ykalinin commentedon Feb 4, 2026
I am currently using Docker (and hope to switch to Apple M4 hardware) as home x86 server. On that server I host different services via Docker containers.
In this case I need to have fixed IP, at least for my local PiHole DNS server (nevertheless some plain IoT devices, which utilise direct IPv4 of services like MQTT or network devices which need to use some static IP to send logs, etc).
I don't really care, if I setup it via --network or --ip (I believe it will increase compatibility with Docker).
mac: persist tor state, rotate bridges only on failure
mac: guarantee container addresses by rebuilding in allocation order
Stage 3 Task 3.2: the macOS per-container restart does not qualify