Skip to content

Instantly share code, notes, and snippets.

@atrisovic
Last active February 19, 2018 16:28
Show Gist options
  • Save atrisovic/673cb77701ada227cb5afc501ad0e7a4 to your computer and use it in GitHub Desktop.
Save atrisovic/673cb77701ada227cb5afc501ad0e7a4 to your computer and use it in GitHub Desktop.
Save/Archive docker images via python from gitlab registry

Step 1:

pip install docker
pip install tqdm

Step 2:

import docker
c = docker.from_env()
p = c.images.pull('gitlab-registry.cern.ch/atrisovi/test-dockint')
img = c.images.get('gitlab-registry.cern.ch/atrisovi/test-dockint:hello')
f = open('/tmp/hello-world.tar','w')
resp = img.save()
import tqdm
for chunk in tqdm.tqdm(resp.stream(), leave=True, miniters=1):
...     f.write(chunk)
...
1it [00:00, 1183.49it/s]
f.close()
exit()

Other

client.images.list()

gitlab registry

from image_importer import ImageImporter
ii = ImageImporter()
ii.archive_image("gitlab-registry.cern.ch/atrisovi/test-dockint:hello", "tmp")

dockerhub

from image_importer import ImageImporter
ii = ImageImporter()
ii.archive_image("atrisovic/rootexample", "tmp")

Repo importer:

from repo_importer import RepoImporter
ri = RepoImporter.create("https://gitlab.cern.ch/atrisovi/root-examples")
s, a = ri.archive_repository()
s
212037
with open("file_repo.tar.gz","w") as f:
...     f.write(a)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment