From dfe8dfc92dbc907adbb2508cd481e3216aa86ca0 Mon Sep 17 00:00:00 2001 From: vinloong <21272660+vinloong@users.noreply.github.com> Date: Sat, 23 Apr 2022 22:52:31 +0800 Subject: [PATCH] add docker sdk --- syncimages/app/docker-util.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 syncimages/app/docker-util.py diff --git a/syncimages/app/docker-util.py b/syncimages/app/docker-util.py new file mode 100644 index 0000000..69537b7 --- /dev/null +++ b/syncimages/app/docker-util.py @@ -0,0 +1,24 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import docker + +client = docker.DockerClient(base_url='unix://var/run/docker.sock') + + +def exist_images(name): + # image = client.images.get('hello-world') + try: + client.images.get(name) + return True + except docker.errors.ImageNotFound: + return False + except docker.errors.APIError as err: + print(err) + + +if __name__ == '__main__': + print(exist_images('alpine:3.15')) + print(exist_images('alpine:latest')) + +