def parseInit(): parser.add_argument("-hn","--hostname", help="the hostname of docker", default=None) parser.add_argument("-n","--name", help="the name of docker container", default=None) parser.add_argument("-p","--port", help="the port of docker binding to host", default=0,type=int) parser.add_argument("-f","--folder",help="the file folder mounted to docker", default=None)
def main(): parseInit() args = parser.parse_args() if len(sys.argv)== 1: print("Use --help or -h to get help.") exit() hostname = args.hostname dockername = args.name port = args.port folder = args.folder
cmd = "docker run -d --rm" if hostname!=None: cmd += " -h "+hostname else: print("[-]No hostname,will not add it")
if dockername!= None: cmd += " --name "+dockername else: print("[-]Container name is needed to exec it or you have to attach to it manually.")
if port!=0: cmd += " -p "+str(port)+":"+str(port) else: print("[-]No port given,will not bind to any port.")
if folder!=None: if os.path.isdir(folder): cmd += " -v "+os.path.realpath(folder)+":/ctf/work" else: print("[-]File path error,will not copy it into container") else: print("[-]File path error,will not copy it")