Giter Site home page Giter Site logo

How to publish ports? about bollard HOT 3 CLOSED

banool avatar banool commented on August 20, 2024
How to publish ports?

from bollard.

Comments (3)

banool avatar banool commented on August 20, 2024 1

Alright here is how you do it:

const POSTGRES_DEFAULT_PORT: u16 = 5432;

fn myfunc(other_port: u16) {
    let port = other_port.to_string();
    let exposed_ports = Some(hashmap! {POSTGRES_DEFAULT_PORT => hashmap!{}});
    let host_config = Some(HostConfig {
        port_bindings: Some(hashmap! {
            POSTGRES_DEFAULT_PORT.to_string() => Some(vec![PortBinding {
                host_ip: Some("127.0.0.1".to_string()),
                host_port: Some(port),
            }]),
        }),
        ..Default::default()
    });

    let config = Config {
        image: Some(POSTGRES_IMAGE),
        exposed_ports,
        host_config,
        ..Default::default()
    };
}

In short, put the inner port in exposed ports and as the key in port bindings, use the outer port in the value of port bindings.

from bollard.

dmartin avatar dmartin commented on August 20, 2024 1

You don't actually need the exposed_ports field to publish a port, only the port_bindings map within host_config.

exposed_ports is equivalent to the docker run --expose flag or Dockerfile EXPOSE statement - it doesn't actually do anything and is basically just a hint for clients regarding which ports should be published.

from bollard.

banool avatar banool commented on August 20, 2024

Ah good to know, ty!

from bollard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.