tag generated container with otherworldowner
label so we know which containers are ours
This commit is contained in:
parent
0b334ea461
commit
6a266323bf
17
otherworld
17
otherworld
@ -8,6 +8,7 @@ import json
|
||||
|
||||
CONTAINER_NAME = "otherworld"
|
||||
DEFAULT_IMAGE_NAME = "debian:stable"
|
||||
OTHERWORLD_LABEL = "otherworldowner"
|
||||
|
||||
def create_x11_mapping ():
|
||||
home = os.environ["HOME"]
|
||||
@ -29,7 +30,7 @@ def create_x11_mapping ():
|
||||
"--shm-size", "2g",
|
||||
"--privileged"]
|
||||
|
||||
DOCKER_CREATE_OPTIONS = ["-t"] + create_x11_mapping()
|
||||
DOCKER_CREATE_OPTIONS = ["-t"]
|
||||
USER_VOLUMES = ["~/otherworld"]
|
||||
BACKGROUND_COMMAND = None
|
||||
DEFAULT_COMMAND = ["bash"]
|
||||
@ -52,8 +53,14 @@ def get_generated_image_name (container_name):
|
||||
def docker_inspect (container):
|
||||
return json.loads(check_output(["docker", "inspect", container]))
|
||||
|
||||
def docker_create (image, container, options, command):
|
||||
docker_command = ["docker", "create", "--name", container] + options + [image]
|
||||
def docker_list_containers (filter_argument):
|
||||
return check_output(["docker", "ps", "-a", "--filter", filter_argument, "--format", "{{.Names}}"]).decode().strip().split("\n")
|
||||
|
||||
def docker_create (image, container, options, command, labels={}):
|
||||
docker_command = ["docker", "create", "--name", container] + options
|
||||
if labels:
|
||||
docker_command = docker_command + list(chain.from_iterable([["--label", f"{kv[0]}={kv[1]}"] for kv in labels.items()]))
|
||||
docker_command.append(image)
|
||||
if command:
|
||||
docker_command = docker_command + command
|
||||
call(docker_command)
|
||||
@ -240,8 +247,8 @@ except Exception:
|
||||
docker_create(
|
||||
image_name,
|
||||
container_name,
|
||||
DOCKER_CREATE_OPTIONS + expand_user_volumes(user_volumes),
|
||||
BACKGROUND_COMMAND
|
||||
DOCKER_CREATE_OPTIONS + create_x11_mapping() + expand_user_volumes(user_volumes),
|
||||
BACKGROUND_COMMAND, { OTHERWORLD_LABEL: user }
|
||||
)
|
||||
container = docker_inspect(container_name)[0]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user