vv9k / podman-api-rs

Rust interface to Podman (libpod).
MIT License
84 stars 12 forks source link

How to get ContainerNetworkConfig or PortBindings #124

Closed dwhiteddsoft closed 2 years ago

dwhiteddsoft commented 2 years ago

I see the struct I need in the model yet dont know of any way to get it. I know that if I run podman container inspect I get this info. Thoughts? Maybe something you are looking for help with?

vv9k commented 2 years ago

As far as I can tell, there currently is no way to get this struct through libpod API. It exists as part of models but is not used in any of the endpoints.

Here is a grep through the current libpod swagger schema:

❯ rg ContainerNetworkConfig /tmp/swagger-v4.2.yaml
770:  ContainerNetworkConfig:
772:      ContainerNetworkConfig contains information on a container's network
dwhiteddsoft commented 2 years ago

Strange though because if I run the following command:

# to start container
podman run -dt --rm -p 8000:80 --name aspnetcore_sample mcr.microsoft.com/dotnet/samples:aspnetapp
# take container ID returned and inspect
podman inspect [container id]

I get the following reply and you can see it in the PortBindings under HostConfig

[
    {
        "Id": "933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c",
        "Created": "2022-07-13T11:23:14.41276992-04:00",
        "Path": "dotnet",
        "Args": [
            "aspnetapp.dll"
        ],
        "State": {
            "OciVersion": "1.0.2-dev",
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 5401,
            "ConmonPid": 5398,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-07-13T11:23:14.488618572-04:00",
            "FinishedAt": "0001-01-01T00:00:00Z",
            "Healthcheck": {
                "Status": "",
                "FailingStreak": 0,
                "Log": null
            }
        },
        "Image": "fd012571eac9111c62cc046a39461c845ef72c4cb987e7dede9c37b4817d9d60",
        "ImageName": "mcr.microsoft.com/dotnet/samples:aspnetapp",
        "Rootfs": "",
        "Pod": "",
        "ResolvConfPath": "/mnt/wslg/runtime-dir/containers/overlay-containers/933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c/userdata/resolv.conf",
        "HostnamePath": "/mnt/wslg/runtime-dir/containers/overlay-containers/933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c/userdata/hostname",
        "HostsPath": "/mnt/wslg/runtime-dir/containers/overlay-containers/933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c/userdata/hosts",
        "StaticDir": "/home/ddsoft/.local/share/containers/storage/overlay-containers/933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c/userdata",
        "OCIConfigPath": "/home/ddsoft/.local/share/containers/storage/overlay-containers/933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c/userdata/config.json",
        "OCIRuntime": "crun",
        "ConmonPidFile": "/mnt/wslg/runtime-dir/containers/overlay-containers/933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c/userdata/conmon.pid",
        "PidFile": "/mnt/wslg/runtime-dir/containers/overlay-containers/933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c/userdata/pidfile",
        "Name": "aspnetcore_sample",
        "RestartCount": 0,
        "Driver": "overlay",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "EffectiveCaps": [
            "CAP_CHOWN",
            "CAP_DAC_OVERRIDE",
            "CAP_FOWNER",
            "CAP_FSETID",
            "CAP_KILL",
            "CAP_NET_BIND_SERVICE",
            "CAP_SETFCAP",
            "CAP_SETGID",
            "CAP_SETPCAP",
            "CAP_SETUID",
            "CAP_SYS_CHROOT"
        ],
        "BoundingCaps": [
            "CAP_CHOWN",
            "CAP_DAC_OVERRIDE",
            "CAP_FOWNER",
            "CAP_FSETID",
            "CAP_KILL",
            "CAP_NET_BIND_SERVICE",
            "CAP_SETFCAP",
            "CAP_SETGID",
            "CAP_SETPCAP",
            "CAP_SETUID",
            "CAP_SYS_CHROOT"
        ],
        "ExecIDs": [],
        "GraphDriver": {
            "Name": "overlay",
            "Data": {
                "LowerDir": "/home/ddsoft/.local/share/containers/storage/overlay/5d4593174664b4088ed4aea199947aaac6a2e6788bc3b44ab5bb2a256400e709/diff:/home/ddsoft/.local/share/containers/storage/overlay/07aef6712bd387955044f386aa03df8cf01cbdf4d926ff062c29661b9e1c5410/diff:/home/ddsoft/.local/share/containers/storage/overlay/47f57f6bb9c9ff5f28936b2d1c70cb372c7e5a0a8efb7430723f7f342922fdfa/diff:/home/ddsoft/.local/share/containers/storage/overlay/3a294a19e2097e4fc8b3702a435acddedca93718f278fa63d49ad07268b9e37a/diff:/home/ddsoft/.local/share/containers/storage/overlay/93cc59ac78fb3ce2fe61953520ae8443cd9c1e3615c50720734e6670e49a576f/diff:/home/ddsoft/.local/share/containers/storage/overlay/9328141e0e623243789ce7ec03cfd61b6d7a2b098bc04948c456c6205b92c3bb/diff:/home/ddsoft/.local/share/containers/storage/overlay/43b3c4e3001c662d1c264ffb132f4e52950893452b15508df810214f1d3f124b/diff",
                "MergedDir": "/home/ddsoft/.local/share/containers/storage/overlay/52d71b570f79d4c4ba9198208c04dbddd8600554b5a46c2e45b2e20caf0fa112/merged",
                "UpperDir": "/home/ddsoft/.local/share/containers/storage/overlay/52d71b570f79d4c4ba9198208c04dbddd8600554b5a46c2e45b2e20caf0fa112/diff",
                "WorkDir": "/home/ddsoft/.local/share/containers/storage/overlay/52d71b570f79d4c4ba9198208c04dbddd8600554b5a46c2e45b2e20caf0fa112/work"
            }
        },
        "Mounts": [],
        "Dependencies": [],
        "NetworkSettings": {
            "EndpointID": "",
            "Gateway": "",
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "MacAddress": "",
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8000"
                    }
                ]
            },
            "SandboxKey": "/mnt/wslg/runtime-dir/netns/cni-590e4707-6eff-9442-751a-2813e0aefab1"
        },
        "ExitCommand": [
            "/usr/bin/podman",
            "--root",
            "/home/ddsoft/.local/share/containers/storage",
            "--runroot",
            "/mnt/wslg/runtime-dir/containers",
            "--log-level",
            "warning",
            "--cgroup-manager",
            "cgroupfs",
            "--tmpdir",
            "/mnt/wslg/runtime-dir/libpod/tmp",
            "--runtime",
            "crun",
            "--storage-driver",
            "overlay",
            "--storage-opt",
            "overlay.mount_program=/usr/bin/fuse-overlayfs",
            "--events-backend",
            "file",
            "container",
            "cleanup",
            "--rm",
            "933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c"
        ],
        "Namespace": "",
        "IsInfra": false,
        "Config": {
            "Hostname": "933978b9f21e",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": true,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "TERM=xterm",
                "container=podman",
                "ASPNETCORE_URLS=http://+:80",
                "DOTNET_RUNNING_IN_CONTAINER=true",
                "DOTNET_VERSION=6.0.7",
                "ASPNET_VERSION=6.0.7",
                "HOME=/root",
                "HOSTNAME=933978b9f21e"
            ],
            "Cmd": null,
            "Image": "mcr.microsoft.com/dotnet/samples:aspnetapp",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": "dotnet aspnetapp.dll",
            "OnBuild": null,
            "Labels": null,
            "Annotations": {
                "io.container.manager": "libpod",
                "io.kubernetes.cri-o.Created": "2022-07-13T11:23:14.41276992-04:00",
                "io.kubernetes.cri-o.TTY": "true",
                "io.podman.annotations.autoremove": "TRUE",
                "io.podman.annotations.init": "FALSE",
                "io.podman.annotations.privileged": "FALSE",
                "io.podman.annotations.publish-all": "FALSE",
                "org.opencontainers.image.stopSignal": "15"
            },
            "StopSignal": 15,
            "CreateCommand": [
                "podman",
                "run",
                "-dt",
                "--rm",
                "-p",
                "8000:80",
                "--name",
                "aspnetcore_sample",
                "mcr.microsoft.com/dotnet/samples:aspnetapp"
            ],
            "Umask": "0022",
            "Timeout": 0,
            "StopTimeout": 10
        },
        "HostConfig": {
            "Binds": [],
            "CgroupManager": "cgroupfs",
            "CgroupMode": "host",
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "k8s-file",
                "Config": null,
                "Path": "/home/ddsoft/.local/share/containers/storage/overlay-containers/933978b9f21e94aade274d2f4a6ac82f45a750173d93747e68ab21b309bf325c/userdata/ctr.log",
                "Tag": "",
                "Size": "0B"
            },
            "NetworkMode": "slirp4netns",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8000"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": true,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": [],
            "CapDrop": [
                "CAP_AUDIT_WRITE",
                "CAP_MKNOD",
                "CAP_NET_RAW"
            ],
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": [],
            "GroupAdd": [],
            "IpcMode": "private",
            "Cgroup": "",
            "Cgroups": "default",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "private",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [],
            "Tmpfs": {},
            "UTSMode": "private",
            "UsernsMode": "",
            "ShmSize": 65536000,
            "Runtime": "oci",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": 0,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": [
                {
                    "Name": "RLIMIT_NOFILE",
                    "Soft": 1048576,
                    "Hard": 1048576
                },
                {
                    "Name": "RLIMIT_NPROC",
                    "Soft": 32768,
                    "Hard": 32768
                }
            ],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "CgroupConf": null
        }
    }
]
vv9k commented 2 years ago

Well, PortBindings are a different thing. I was talking about ContainerNetworkConfig that is missing.

PortBindings can be found when you inspect a container here: HostConfig -> https://docs.rs/podman-api/latest/podman_api/models/struct.LibpodContainerInspectResponse.html#structfield.host_config PortBindings -> https://docs.rs/podman-api/latest/podman_api/models/struct.InspectContainerHostConfig.html#structfield.port_bindings

dwhiteddsoft commented 2 years ago

I am going to close this as the combination of the above gives what is needed. Thanks for the help