diff --git a/Dockerfile b/Dockerfile index 2b8b8ec..9b3e7f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,11 @@ FROM alpine:3.11.3 +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories + RUN apk --no-cache update && apk add --no-cache python3 wget \ && wget -q --no-check-certificate https://bootstrap.pypa.io/get-pip.py \ && apk del wget && python3 get-pip.py && rm -f get-pip.py \ - && pip install -U docker pip && yes | pip uninstall pip + && pip install -U docker pip -i https://pypi.tuna.tsinghua.edu.cn/simple && yes | pip uninstall pip RUN mkdir /app COPY entrypoint.sh /. diff --git a/dedockify.py b/dedockify.py index 95a9220..96c75d7 100755 --- a/dedockify.py +++ b/dedockify.py @@ -2,6 +2,7 @@ from sys import argv import docker +import docker.errors class ImageNotFound(Exception): pass @@ -11,9 +12,9 @@ class MainObj: def __init__(self): super(MainObj, self).__init__() self.commands = [] - self.cli = docker.APIClient(base_url='unix://var/run/docker.sock') + self.cli = docker.client.from_env() self._get_image(argv[-1]) - self.hist = self.cli.history(self.img['RepoTags'][0]) + self.hist = self.img.history() self._parse_history() self.commands.reverse() self._print_commands() @@ -23,12 +24,12 @@ def _print_commands(self): print(i) def _get_image(self, img_hash): - images = self.cli.images() - for i in images: - if img_hash in i['Id']: - self.img = i - return - raise ImageNotFound("Image {} not found\n".format(img_hash)) + try: + img = self.cli.images.get(img_hash) + self.img = img + except docker.errors.ImageNotFound: + raise ImageNotFound("Image {} not found".format(img_hash)) + def _insert_step(self, step): if "#(nop)" in step: @@ -52,4 +53,4 @@ def _parse_history(self, rec=False): self.commands.append("FROM {}".format(actual_tag)) -__main__ = MainObj() +__main__ = MainObj() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index fe88db8..0fb3792 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -docker-py==1.10.6 +docker==7.1.0