Skip to content
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
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@ Unpacks a Docker image.

## Usage

usage: undocker.py [-h] [--ignore-errors] [--output OUTPUT] [--verbose]
[--debug] [--list] [--layer LAYER]
image
usage: undocker [-h] [--ignore-errors] [--output OUTPUT] [--layers] [--list]
[--layer LAYER] [--no-whiteouts] [--verbose] [--debug]
[image]

positional arguments:
image
image The docker image tar archive from `docker save`. Read
from stdin if left empty.

optional arguments:
-h, --help show this help message and exit
--ignore-errors, -i Ignore OS errors when extracting files
--output OUTPUT, -o OUTPUT
Output directory (defaults to ".")
--verbose, -v
--debug, -d
--list, --ls List layers in an image
--layers List layers in an image
--list, --ls List images/tags contained in archive
--layer LAYER, -l LAYER
Extract only the specified layer
--no-whiteouts, -W Do not process whiteout (.wh.*) files

Logging options:
--verbose, -v
--debug, -d

## Examples

Extract an entire image:

$ docker save busybox | undocker -i -o busybox busybox
$ docker save busybox | undocker -i -o busybox

The `-i` option is necessary here because I am not running as root,
and the extract operation will fail when it attempts to create device
Expand All @@ -42,14 +47,13 @@ Extract only specific layers:

$ docker save busybox |
undocker -o busybox -v \
-l 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125 \
busybox
-l 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
INFO:undocker:extracting image busybox (4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125)
INFO:undocker:extracting layer 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125

## License

undocker -- a tool for decomposing Docker images
undocker -- a tool for decomposing Docker images
Copyright (C) 2015 Lars Kellogg-Stedman <lars@oddbit.com>

This program is free software: you can redistribute it and/or modify
Expand Down
5 changes: 4 additions & 1 deletion undocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def parse_args():
const=logging.DEBUG,
dest='loglevel')

p.add_argument('image', nargs='?')
p.add_argument('image', nargs='?', help='The docker image tar archive from `docker save`. Read from stdin if left empty.')

p.set_defaults(level=logging.WARN)
return p.parse_args()
Expand Down Expand Up @@ -95,6 +95,9 @@ def main():
args = parse_args()
logging.basicConfig(level=args.loglevel)

if args.image and not os.path.exists(args.image):
raise Exception(f'Expected "{args.image}" to be a docker image tar file.')

with tempfile.NamedTemporaryFile() as fd, (
open(args.image, 'rb') if args.image
else io.open(sys.stdin.fileno(), 'rb')) as image:
Expand Down