Skip to content

[Request]: A direct option to assign or configure the container's IP address #282

Description

@danielcamargo

Feature or enhancement request details

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

Activity

  1. added theissue type on Jul 1, 2025
  2. jglogan commented on Jul 1, 2025

    @jglogan
    Contributor

    @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.

  3. nhuphucnguyen commented on Jul 1, 2025

    @nhuphucnguyen

    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.

    1. https://github.com/apple/container/blob/main/docs/tutorial.md#set-up-a-local-dns-domain-optional
    2. https://github.com/apple/container/blob/main/docs/tutorial.md#access-the-web-server-from-another-container
    3. 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
  4. Mcrich23 commented on Jul 9, 2025

    @Mcrich23
    Contributor

    Thanks @jglogan. This also seems very important for making technologies like Vapor usable with containers.

  5. planetprivate commented on Jul 10, 2025

    @planetprivate

    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 sh
    and I install inside it sshserver.
    How does one ssh to the ubuntu server running?

    Is this possible? Many thanks

  6. jglogan commented on Jul 11, 2025

    @jglogan
    Contributor

    @planetprivate If you had:

    container run —publish 0.0.0.0:8000:8000 …

    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.

  7. planetprivate commented on Jul 12, 2025

    @planetprivate

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

    Thanks!

  8. jglogan commented on Jul 16, 2025

    @jglogan
    Contributor

    @planetprivate

    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.

  9. jglogan commented on Jul 31, 2025

    @jglogan
    Contributor

    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.
    • Update SandboxService to use the new call
  10. added
    facet/network
    on Aug 6, 2025
  11. marcobarrios-fi commented on Aug 11, 2025

    @marcobarrios-fi

    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.

  12. jglogan commented on Jan 8, 2026

    @jglogan
    Contributor

    First off, regarding:

    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.
  13. ykalinin commented on Feb 4, 2026

    @ykalinin
    • 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    facet/network

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions