def remove_dangling(docker):
    try:
        dangling_images_ids = \
        [id['Id'].encode('utf-8') for id in docker.images(filters={'dangling': True})]
        for id in dangling_images_ids:
            docker.remove_image(image=id, force=True, noprune=False)
            print '%s image removed' % id
    except Exception,e:
        print 'type: %s' % type(e)
        print 'args: %s' % e.args
        print str(e)
def remove_images(docker, composefile_name, dangling=False):
    try:
        if dangling:
            dangling_images_ids = [id["Id"].encode("utf-8") for id in docker.images(filters={"dangling": True})]
            for id in dangling_images_ids:
                docker.remove_image(image=id, force=True, noprune=False)
                print "%s image removed" % id
        with open(composefile_name, "r") as ymlfile:
            cfg = yaml.load(ymlfile)
        for service in cfg:
            exist, iname = check_image_name(docker, service)
            if exist:
                docker.remove_image(image=iname, force=True, noprune=False)
                print "%s image removed" % iname
    except Exception, e:
        print "type: %s" % type(e)
        print "args: %s" % e.args
        print str(e)
Example #3
0
def docker_function():
    os.system("clear")
    cprint = TextFormatter()
    os.system("figlet -tc Docker")
    cprint.cfg("b", "k", "b")
    cprint.center(
        "Installing and Starting Docker on this system, please wait ...\n")
    cprint.reset()
    start_docker_service()
    i = 0
    while (True):
        if i == 0:
            pass
        else:
            os.system("clear")
            cprint = TextFormatter()
            os.system("figlet -tc Docker")
        cprint.cfg("g", "k", "b")
        cprint.center(
            "Docker service has been started on base system, please choose below options\n"
        )
        cprint.reset()
        cprint.cfg("y", "k", "i")
        print("-" * c, "\n")
        cprint.out("\t\t\t\t a. \t Pulling Image")
        cprint.out("\t\t\t\t b. \t Launching Container")
        cprint.out("\t\t\t\t c. \t Remove Image")
        cprint.out("\t\t\t\t d. \t Remove Container")
        cprint.out("\t\t\t\t e. \t Copy files from Base system to Continer")
        cprint.out("\t\t\t\t f. \t Copy files from Container to Base system")
        cprint.out("\t\t\t\t g. \t Check running containers")
        cprint.out("\t\t\t\t h. \t Check all containers (running or stopped)")
        cprint.out("\t\t\t\t i. \t To start the initially created container")
        cprint.out("\t\t\t\t j. \t Stop the running container")
        cprint.out("\t\t\t\t k. \t View all docker Images")
        cprint.out("\t\t\t\t l. \t Inspect docker container")
        cprint.out(
            "\t\t\t\t m. \t Remove all the container(Be sure with this option)"
        )
        cprint.out("\t\t\t\t n. \t Check IP Address of container\n")

        cprint.out(
            "\t\t\t\t o. \t Build Apache WebServer Image using Dockerfile")
        cprint.out("\t\t\t\t p. \t Run WebServer\n")

        cprint.reset()
        cprint.cfg("c", "k", "y")
        cprint.out("\t\t\t\t Press ~ to go back to main menu.\n\n")

        di = input("\t\t\t\tEnter your choice : ")
        if di == "a":
            os.system("clear")
            pull_image()
        elif di == "b":
            os.system("clear")
            launch_container()
        elif di == "c":
            os.system("clear")
            remove_image()
        elif di == "d":
            remove_container()
        elif di == "e":
            os.system("clear")
            cp_base_to_cont()
        elif di == "f":
            os.system("clear")
            cp_cont_to_base()
        elif di == "g":
            os.system("clear")
            see_the_running_cont()
        elif di == "h":
            see_all_cont()
        elif di == "i":
            os.system("clear")
            start_exist_cont()
        elif di == "j":
            os.system("clear")
            stop_running_docker()
        elif di == "k":
            os.system("clear")
            get_images()
        elif di == "l":
            os.system("clear")
            inspect_docker()
        elif di == "m":
            os.system("clear")
            remove_allcont()
        elif di == "n":
            os.system("clear")
            docker_ip()
        elif di == "o":
            os.system("clear")
            build_apacheServer_image_dockerfile()
        elif di == "p":
            os.system("clear")
            runWebServer()
        elif di == "~":
            menu()
        else:
            print("\nPlease enter correct option")
        i = i + 1
        q = input(
            "\n\n\n\t\t\t\t To continue press(c) or to go back to main menu press(b) : "
        )
        os.system("clear")
        if q == "b" or q == "B":
            menu()
Example #4
0
def delete_image(repository: Any, image_digest: str) -> None:
    """
    Remove image from Docker registry
    """
    docker.remove_image(image_digest)