fussybeaver / bollard

Docker daemon API in Rust
Apache License 2.0
893 stars 134 forks source link

Why does exposed_ports in the Config struct have the type that it does? #366

Closed bpmooch closed 8 months ago

bpmooch commented 9 months ago

https://github.com/fussybeaver/bollard/blob/bfedd5c4fb01180a805b8772154f1e99cd7e927e/src/container.rs#L155

Basically I'm asking why HashMap<&str, HashMap<(), ()>> vs something simpler like Vec<String>?

fussybeaver commented 9 months ago

Bollard aligns with the Swagger specification as much as possible:

https://github.com/moby/moby/blob/master/api/swagger.yaml#L1230-L1245

As the example is "80/tcp": {} this translates to HashMap<&str, HashMap<(), ()>>

bpmooch commented 9 months ago

Ok, thanks for the clarification on the shape of the API.

I am finding that I don't understand how to create the right hashmap such that 9000/tcp is exposed on localhost for a container I start with bollard. For clarification, I am attempting to emulate docker run -d --rm -p "9000:9000" minio/minio:latest server /data with the following bollard::container::Config :

    let minio_config = Config {
        image: Some(MINIO_IMAGE),
        exposed_ports: Some(HashMap::from([
            ("9000:9000", empty.clone()),
            // ("9001:9001", empty.clone()),
        ])),
        env: Some(vec![
            "MINIO_ROOT_USER=testuser",
            "MINIO_ROOT_PASSWORD=testpass",
        ]),
        // no need to start console when controlling with docker exec and opendal
        cmd: Some(vec!["server", "/data"]),
        ..Default::default()
    };

Am I using the wrong part of the API to accomplish this?

After some more investigation, it looks like I should be utilizing host_config?

dmartin commented 9 months ago

After some more investigation, it looks like I should be utilizing host_config?

Yep, exposing and publishing ports are different. See similar discussion in this issue: https://github.com/fussybeaver/bollard/issues/340

bpmooch commented 9 months ago

Thank you! This issue can be closed now