vinloong
3 years ago
1 changed files with 24 additions and 0 deletions
@ -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')) |
||||
|
|
||||
|
|
Reference in new issue