confd: add support for setting container hostname

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-02-25 19:49:27 +01:00
parent 7a57d4f0fa
commit aa7ea66a0d
3 changed files with 17 additions and 4 deletions
+7 -2
View File
@@ -46,8 +46,8 @@ create()
fi
# --syslog --log-level info
log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $env $network $port $args $image\""
if podman create --name "$name" --conmon-pidfile="$pidfn" $env $network $port $args "$image"; then
log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $hostname $env $network $port $args $image\""
if podman create --name "$name" --conmon-pidfile="$pidfn" $hostname $env $network $port $args "$image"; then
log "Successfully created container $name from $image"
rm "/run/containers/env/${name}.env"
initctl show "container:$name" |grep -q manual:yes || initctl -bq start "container:$name"
@@ -87,6 +87,7 @@ options:
-e, --env FILE Environment variables when creating container
-f, --force Force operation, e.g. remove
-h, --help Show this help text
--hostname NAME Set hostname when creating container
-p, --publish PORT Publish ports when creating container
Syntax: [[ip:][hostPort]:]containerPort[/protocol]
-s, --simple Show output in simplified format
@@ -129,6 +130,10 @@ while [ "$1" != "" ]; do
usage
exit 0
;;
--hostname)
shift
hostname="--hostname $1"
;;
-p | --publish)
shift
port="$port -p $1"
+4 -1
View File
@@ -29,7 +29,7 @@ static const struct srx_module_requirement reqs[] = {
static int add(const char *name, struct lyd_node *cif)
{
const char *image = lydx_get_cattr(cif, "image");
const char *restart_policy;
const char *restart_policy, *string;
struct lyd_node *node;
FILE *fp, *ep = NULL;
char *restart = ""; /* Default restart:10 */
@@ -52,6 +52,9 @@ static int add(const char *name, struct lyd_node *cif)
LYX_LIST_FOR_EACH(lyd_child(cif), node, "search")
fprintf(fp, " --dns-search %s", lyd_get_value(node));
if ((string = lydx_get_cattr(cif, "hostname")))
fprintf(fp, " --hostname %s", string);
LYX_LIST_FOR_EACH(lyd_child(cif), node, "publish")
fprintf(fp, " -p %s", lyd_get_value(node));
@@ -83,6 +83,11 @@ module infix-containers {
}
}
leaf hostname {
description "Sets the container host name that is available inside the container.";
type inet:domain-name;
}
leaf image {
description "Docker image used for the container";
mandatory true;
@@ -104,7 +109,7 @@ module infix-containers {
description "Select network mode: none, host, or container network interfaces.";
case host-network {
leaf host {
leaf host-network {
description "Run in same network namespace as host.";
type boolean;
}