def docker_run(ctx, docker_run_args, help): """Simple docker wrapper that adds WANDB_API_KEY and WANDB_DOCKER to any docker run command. This will also set the runtime to nvidia if the nvidia-docker executable is present on the system and --runtime wasn't set. """ args = list(docker_run_args) if len(args) > 0 and args[0] == "run": args.pop(0) if help or len(args) == 0: wandb.termlog("This commands adds wandb env variables to your docker run calls") subprocess.call(['docker', 'run'] + args + ['--help']) exit() #TODO: is this what we want? if len([a for a in args if a.startswith("--runtime")]) == 0 and find_executable('nvidia-docker'): args = ["--runtime", "nvidia"] + args #TODO: image_from_docker_args uses heuristics to find the docker image arg, there are likely cases #where this won't work image = util.image_from_docker_args(args) resolved_image = None if image: resolved_image = wandb.docker.image_id(image) if resolved_image: args = ['-e', 'WANDB_DOCKER=%s' % resolved_image] + args else: wandb.termlog("Couldn't detect image argument, running command without the WANDB_DOCKER env variable") if api.api_key: args = ['-e', 'WANDB_API_KEY=%s' % api.api_key] + args else: wandb.termlog("Not logged in, run `wandb login` from the host machine to enable result logging") subprocess.call(['docker', 'run'] + args)
def test_image_from_docker_args_sha(): dsha = ("wandb/deepo@sha256:" "3ddd2547d83a056804cac6aac48d46c5394a76df76b672539c4d2476eba38177") image = util.image_from_docker_args([dsha]) assert image == dsha
def test_image_from_docker_args_bash_simple(): image = util.image_from_docker_args( ["run", "ufoym/deepo:cpu-all", "/bin/bash", "-c", "python train.py"]) assert image == "ufoym/deepo:cpu-all"
def test_image_from_docker_args_simple_no_equals(): image = util.image_from_docker_args( ["run", "--runtime=runc", "ufoym/deepo:cpu-all"]) assert image == "ufoym/deepo:cpu-all"
def test_image_from_docker_args_simple_no_namespace(): image = util.image_from_docker_args( ["run", "-e", "NICE=foo", "nginx", "/bin/bash"]) assert image == "nginx"
def test_image_from_docker_args_simple(): image = util.image_from_docker_args([ "run", "-v", "/foo:/bar", "-e", "NICE=foo", "-it", "wandb/deepo", "/bin/bash" ]) assert image == "wandb/deepo"