Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat - Adapt to the latest version of Docker. #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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 /.
Expand Down
19 changes: 10 additions & 9 deletions dedockify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from sys import argv
import docker
import docker.errors

class ImageNotFound(Exception):
pass
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -52,4 +53,4 @@ def _parse_history(self, rec=False):
self.commands.append("FROM {}".format(actual_tag))


__main__ = MainObj()
__main__ = MainObj()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker-py==1.10.6
docker==7.1.0