added python Testskript

This commit is contained in:
nutzer26
2022-12-13 12:03:41 +01:00
parent 4f6426ff6f
commit 429971c44a
3 changed files with 135 additions and 12 deletions

11
docker_restapi Normal file
View File

@@ -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

105
docker_sheets Normal file
View File

@@ -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 containers file system as a tar archive
$ docker container export
This command is used create a new image from a containers 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

View File

@@ -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():
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
# Mit eval kann ich ein String zum Command ausführen !!!!
print(read_all_container()["container"])
def show_docker_con_img(input):
output_list = []
client = docker.from_env()
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(show_docker_con_img("containers"))
#print(show_docker_con_img("images"))