From 488dedb74e2d03dda5444ef79a0b80d3a5862fb6 Mon Sep 17 00:00:00 2001 From: Adrian Malacoda Date: Sat, 3 Apr 2021 01:23:49 -0500 Subject: [PATCH] Add user_init_command config option, to specify an additional command that should be run when the container is created. --- otherworld | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/otherworld b/otherworld index ba91007..f14f6b5 100755 --- a/otherworld +++ b/otherworld @@ -245,7 +245,8 @@ config = { "command_env": {}, "cwd": os.getcwd(), "tty": sys.stdout.isatty(), - "log": log + "log": log, + "user_init_command": [] } # load config from files @@ -336,5 +337,11 @@ except Exception: log("Creating container user: {}", user) docker_create_user(container_name, user, uid) + if config['user_init_command']: + user_init_command = config['user_init_command'] + if isinstance(user_init_command, str): + user_init_command = ["sh", "-c", user_init_command] + docker_exec(container_name, user_init_command, command_user, command_env, tty, "/home/{}".format(command_user)) + log("Welcome to {} (IP {})", container_name, container['NetworkSettings']['IPAddress']) docker_exec(container_name, command, command_user, command_env, tty, command_workdir)