From 429971c44a6c4d4d653c3d096c5638475fd07a78 Mon Sep 17 00:00:00 2001 From: nutzer26 Date: Tue, 13 Dec 2022 12:03:41 +0100 Subject: [PATCH] added python Testskript --- docker_restapi | 11 +++++ docker_sheets | 105 +++++++++++++++++++++++++++++++++++++++++++++++ python_docker.py | 31 ++++++++------ 3 files changed, 135 insertions(+), 12 deletions(-) create mode 100644 docker_restapi create mode 100644 docker_sheets diff --git a/docker_restapi b/docker_restapi new file mode 100644 index 0000000..224cbbc --- /dev/null +++ b/docker_restapi @@ -0,0 +1,11 @@ +# Docker engine use a REST API +curl -s --unix-socket /var/run/docker.sock http://v1.32/info | jq "." +curl -s --unix-socket /var/run/docker.sock http://v1.41/info | jq "." +docker image save -o nginx.tar nginx:1.19.3 +tar tf nginx.tar +docker image load -i nginx.tar +#docker container export ... +#docker image import ... + +# docker api Starten. +docker container run -v /var/run/docker.sock:/var/run/docker.sock --rm -t docker docker container ls diff --git a/docker_sheets b/docker_sheets new file mode 100644 index 0000000..f490d01 --- /dev/null +++ b/docker_sheets @@ -0,0 +1,105 @@ + List of Common Docker commands + +This command is used to run a command in a new container. + + $ docker container run + +This command is used to start one or more stopped containers. + + $ docker container start + +This command is used to stop one or more running containers. + + $ docker container stop + +This command is used to restart one or more containers. + + $ docker container restart + +This command is used to remove one or more docker containers. + + $ docker container rm + +This command is used to run a command in a run-time container + + $ docker container exec + +This command is used attach to a running container + + $ docker container attach + +This command is used to fetch all the running containers. + + $ docker container ls + +This command forcefully terminates the container execution. + + $ docker container kill + +This command is used to copy files/folders between a container and the local machine. + + $ docker container cp + +This command is used to rename a container. + + $ docker container rename + +This command is used to fetch the logs of a container. + + $ docker container logs + +This command is used to build an image form a Docker file. + + $ docker build + +This command is used push an image or a repository to a registry. + + $ docker image push + +This command is used pull an image or a repository from a registry. + + $ docker image pull + +This command is used to search the Docker Hub for images + + $ docker search + +This command is used export a container’s file system as a tar archive + + $ docker container export + +This command is used create a new image from a container’s changes + + $ docker container commit + +This command is used to show the history of an image. + + $ docker image history + +This command is used to remove one or more images. + + $ docker image rm + +This command is used to log in to a Docker registry. + + $ docker login + +This command is used to log out from a Docker registry. + + $ docker logout + +This command is used to extract docker version information. + + $ docker version + +This command is used to fetch the real time events from the server. + + $ docker events + +This command is used to manage the Plugins. + + $ docker plugin + +This command is used to manage Docker configuration. + + $ docker config \ No newline at end of file diff --git a/python_docker.py b/python_docker.py index ef3fd24..aa005ea 100644 --- a/python_docker.py +++ b/python_docker.py @@ -2,18 +2,25 @@ import docker -client = docker.from_env() -#print(client.info()["ContainersRunning"]) -AllImage = client.images.list(all=True) +#client = docker.from_env() -def read_all_container(): +# Mit eval kann ich ein String zum Command ausführen !!!! + +def show_docker_con_img(input): + output_list = [] client = docker.from_env() - AllContainer = client.containers.list(all=True) - low_list= [] - for con in AllContainer: - test = str(con).split(":") - low_list.append(test[1].replace(">", "")) - con_dict = {"container" : low_list} - return con_dict + if input == "images": + search_query = "RepoTags" + test = 'client.' + input + '.list(all=True)' + if input == "containers": + search_query = "Id" + test = 'client.' + input + '.list(all=True)' + else: + raise InterruptedError("Die Funktion nutzt nur als input : \n images \n containers") + for i in eval(test): + query_Tags = "".join(i.attrs[search_query]) + output_list.append(query_Tags) + return output_list -print(read_all_container()["container"]) \ No newline at end of file +print(show_docker_con_img("containers")) +#print(show_docker_con_img("images"))