Search code examples
podman

Assigning specific IP address to Containers using Podman


Everytime that I create a container from an image using Podman, I'd like assign a specific IP address to it. Currently each time I create a new container, the IP address increases by 1 starting from 10.88.0.1


Solution

  • you can use --ip flag:

    podman run --rm -it --systemd=always --ip=10.88.0.17 --rootfs /busterr /sbin/init
    

    you can list what is the range of ip's podman will accept with ip a , in the host do:

    # ip a
    6: cni-podman0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
        inet 10.88.0.1/16 brd 10.88.255.255 scope global cni-podman0
    ...
    

    10.88.0.1/16 means that you can choose an ip between 10.88.0.2 and 10.88.255.255

    with this you will always have the same ip 10.88.0.17.