Skip to content

Commit 6be2cf2

Browse files
committed
common: add support for default_host_ip in containers.conf
This adds support for configuring a default host IP via containers.conf to bind published container ports to when no host IP is explicitly specified (e.g. -p 8000:8000). Note that explicit host IP still overrides the default option set in containers.conf. Refers containers/podman#27186 Signed-off-by: Danish Prakash <[email protected]>
1 parent cacf855 commit 6be2cf2

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

common/docs/containers.conf.5.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,17 @@ run on the machine.
525525
A list of default pasta options that should be used running pasta.
526526
It accepts the pasta cli options, see pasta(1) for the full list of options.
527527

528+
**default_host_ips**=[]
529+
530+
The default host IPs to bind published container ports to when no host IP
531+
is explicitly specified in the `-p` flag (e.g., `-p 8000:8000`). If empty, the default
532+
behavior is to bind to all network interfaces (`0.0.0.0`). If multiple IPs are specified,
533+
separate port mapping for each of the specified IP would be created. For instance, setting
534+
this to `["127.0.0.1", "::1"]` and port specified as `-p 8080:80` will result into two
535+
port mappings in podman--`127.0.0.1:8080:80` and `[::1]:8080:80`.
536+
Note that explicitly specifying a host IP in the `-p` flag (e.g., `-p 192.168.1.10:8000:8000`)
537+
will always override this default.
538+
528539
## ENGINE TABLE
529540
The `engine` table contains configuration options used to set up container engines such as Podman and Buildah.
530541

common/pkg/config/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,13 @@ type NetworkConfig struct {
634634
// PastaOptions contains a default list of pasta(1) options that should
635635
// be used when running pasta.
636636
PastaOptions attributedstring.Slice `toml:"pasta_options,omitempty"`
637+
638+
// DefaultHostIPs is the default host IPs to bind published container ports
639+
// to when no host IP is explicitly specified in the -p flag (e.g., -p 80:80).
640+
// If empty, the default behavior is to bind to all interfaces (0.0.0.0).
641+
// If multiple IPs are specified, separate port mapping for each of the specified
642+
// IP would be created.
643+
DefaultHostIPs []string `toml:"default_host_ips,omitempty"`
637644
}
638645

639646
type SubnetPool struct {

common/pkg/config/containers.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ default_sysctls = [
445445
#
446446
#pasta_options = []
447447

448+
# The default host IPs to bind published container ports to when no host IP
449+
# is explicitly specified in the -p flag (e.g., -p 8000:8000). If empty, the default
450+
# behavior is to bind to all network interfaces (0.0.0.0). If multiple IPs are specified,
451+
# separate port mapping for each of the specified IP would be created. For instance, setting
452+
# this to ["127.0.0.1", "::1"] and port specified as -p 8080:80 will result into two
453+
# port mappings in podman--127.0.0.1:8080:80 and [::1]:8080:80.
454+
# Note that explicitly specifying a host IP via -p will always override this.
455+
#
456+
#default_host_ips = []
457+
448458
[engine]
449459
# Index to the active service
450460
#

common/pkg/config/containers.conf-freebsd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ default_sysctls = [
335335
#
336336
#network_config_dir = "/usr/local/etc/cni/net.d/"
337337

338+
# The default host IPs to bind published container ports to when no host IP
339+
# is explicitly specified in the -p flag (e.g., -p 8000:8000). If empty, the default
340+
# behavior is to bind to all network interfaces (0.0.0.0). If multiple IPs are specified,
341+
# separate port mapping for each of the specified IP would be created. For instance, setting
342+
# this to ["127.0.0.1", "::1"] and port specified as -p 8080:80 will result into two
343+
# port mappings in podman--127.0.0.1:8080:80 and [::1]:8080:80.
344+
# Note that explicitly specifying a host IP via -p will always override this.
345+
#
346+
#default_host_ips = []
347+
338348
[engine]
339349
# Index to the active service
340350
#

0 commit comments

Comments
 (0)