Commit dfc3acd9 authored by Grant's avatar Grant
Browse files

add execute and mount script

parent 371ad375
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -22,4 +22,16 @@ def remove_volumes(prefix):
    subprocess.run(command, shell=True)


docker.add_command(docker)
 No newline at end of file
@docker.command(name='docker-execute-and-mount',
                help='Execute a command in a docker container with a /tmp as the pwd.')
@click.option('--image', '-i', default='python:3.11-latest', help='Docker image to use.')
@click.option('--volume-target', '-t', default=None, help='Target directory to mount.')
@click.option('--volume-mount', '-m', default='/tmp', help='Mount directory inside the container.')
@click.option('--exec', '-e', 'exec_cmd', default='bash', help='Command to execute.')
def docker_execute_and_mount(image, volume_target, volume_mount, exec_cmd):
    """Execute a command in a docker container with a /tmp as the pwd."""
    if not volume_target:
        volume_target = os.getcwd()
    command = f"docker run -it -v {volume_target}:{volume_mount} -w {volume_mount} {image} {exec_cmd}"
    subprocess.run(command, shell=True)