Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/realityone/docker-image-py
Parse docker image as distribution does.
https://github.com/realityone/docker-image-py
docker-image python
Last synced: 28 days ago
JSON representation
Parse docker image as distribution does.
- Host: GitHub
- URL: https://github.com/realityone/docker-image-py
- Owner: realityone
- License: apache-2.0
- Created: 2016-11-10T13:39:16.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-17T05:31:20.000Z (4 months ago)
- Last Synced: 2024-09-27T01:52:22.725Z (about 1 month ago)
- Topics: docker-image, python
- Language: Python
- Size: 40 KB
- Stars: 20
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# docker-image-py
Parse docker image as distribution does.## Usage
### Install
You can install from PyPI.
```shell
$ pip install docker-image-py
```Or install from GitHub for latest version.
```shell
$ pip install https://github.com/realityone/docker-image-py/archive/master.zip
```### Parse Docker Image
```python
>>> from docker_image import reference
>>>
>>> # with registry, repo, tag, and digest
>>> ref = reference.Reference.parse(
... 'daocloud.io/nginx:1.11-alpine@sha256:14bf491df1d58404433b577e093c906460871ee677d18caa276d9c03727e0b33'
... )
>>> print ref
{'tag': '1.11-alpine', 'name': 'daocloud.io/nginx', 'digest': 'sha256:14bf491df1d58404433b577e093c906460871ee677d18caa276d9c03727e0b33'}
>>>
>>> # with registry and repo
>>> ref = reference.Reference.parse(
... 'daocloud.io/nginx'
... )
>>> print ref
{'tag': None, 'name': 'daocloud.io/nginx', 'digest': None}
>>> # get registry hostname
>>> hostname, name = ref.split_hostname()
>>> print 'hostname: {}, name: {}'.format(hostname, name)
hostname: daocloud.io, name: nginx
>>> # with registry, repo and tag
>>> ref = reference.Reference.parse(
... 'daocloud.io/nginx:latest'
... )
>>> print ref
{'tag': 'latest', 'name': 'daocloud.io/nginx', 'digest': None}
>>> # with repo and tag
>>> ref = reference.Reference.parse(
... 'nginx:latest'
... )
>>> print ref
{'tag': 'latest', 'name': 'nginx', 'digest': None}
>>> # only repo
>>> ref = reference.Reference.parse(
... 'nginx'
... )
>>> print ref
{'tag': None, 'name': 'nginx', 'digest': None}
>>> ref = reference.Reference.parse_normalized_named(
... 'containous/traefik'
... )
>>> print ref
{'name': 'docker.io/containous/traefik', 'tag': None, 'digest': None}
>>> hostname, name = ref.split_hostname()
>>> print 'hostname: {}, name: {}'.format(hostname, name)
hostname: docker.io, name: containous/traefik
```## Reference
- https://github.com/docker/distribution/tree/master/reference