Prefix container hostname with the underlying one

To make it easier to identity where a docker container is running,
prefix its hostname with the underlying one from the host.

Docker chooses a 12 character random hex string by default, so we'll
keep that as the suffix.
This commit is contained in:
Donal McBreen
2023-05-31 16:17:15 +01:00
parent de2de19434
commit 28d6a131a9
4 changed files with 25 additions and 6 deletions

View File

@@ -8,17 +8,18 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
@role = role
end
def start_or_run
combine start, run, by: "||"
def start_or_run(hostname: nil)
combine start, run(hostname: hostname), by: "||"
end
def run
def run(hostname: nil)
role = config.role(self.role)
docker :run,
"--detach",
"--restart unless-stopped",
"--name", container_name,
*(["--hostname", hostname] if hostname),
"-e", "MRSK_CONTAINER_NAME=\"#{container_name}\"",
*role.env_args,
*role.health_check_args,