An open API service indexing awesome lists of open source software.

https://github.com/garfieldius/docktar

Create docker friendly tars with binaries for single ADD commands
https://github.com/garfieldius/docktar

docker docker-image dockerfile tar

Last synced: about 2 months ago
JSON representation

Create docker friendly tars with binaries for single ADD commands

Awesome Lists containing this project

README

          

# docktar

docktar is a small script / program that adds one or more binary files,
with all dynamic libraries they need into a single tar archive file.

This allows for creating much smaller and easier to maintain docker
images by adding only the data required.

It can, optionally, strip debugging symbols from binary files and
add non-executable files, like configrations or data files, without
processing them.

**Important**: docktar only works on linux systems with linux binaries!

## Installation

With a properly setup go environment, `go get` will install the latest version:

```bash
go get github.com/garfieldius/docktar
```

Ready to use binaries can be found in the releases section. After the download
they must be put into a directory in $PATH and marked executable.

## Usage

### Running docktar

#### Creating archives

docktar is started on a command line with one or several full filepaths as arguments.

```bash
docktar $(which gawk) /bin/sed
```

The file will have the same filepath within the tar archive. A different path is set
by adding it after the source path, divided by a colon:

```bash
docktar /usr/bin/gawk:/bin/awk
```

If the file path is relative it will be expanded to absolute. Files in $PATH can be
added without a directory in the argument. Docktar will add them with the directory
they are found in.

```bash
docktar awk # Adds awk as "/usr/bin/awk"
```

Note that symlinks are resolved, but not added. So if the above example is
a link to `/usr/bin/gawk`, the content of the link target is added under the name
of the link itself.

The following three commands will create the same tar archive:

```bash
docktar awk
docktar $(which awk)
docktar $(readlink $(which awk)):/usr/bin/awk
```

Multiple files can be added with multiple arguments and/or globbing. When using
the latter, escape the argument to ensure the pattern is not expaned by the shell:

```bash
# Add PHP for CLI and FPM, and all its extensions and ini files
docktar php php-fpm "/usr/lib/php/**/*.so" "/etc/php/**/*.ini"
```

#### Switches

By default, docktar will save the resulting archive in a file named `docker.tar`
within the current working directory. The `-o` flag sets a different filename.
Setting `-o` to `-` will write the archive to stdout:

```bash
docktar -o sed.tar /bin/sed
# or
docktar -o - /bin/sed > sed.tar
```

With the `-s` switch, all files will be stripped of debugging symbols. This
required the program `strip` to be installed.

```bash
docktar -s $(which sed)
```

Adding `-d` creates a `Dockerfile` next to the written .tar file, containing
the minimum commands to create an image.

### Using the archive

A Dockerfile that starts from `scratch` and `ADD`s the archive into `/` will
place the content of the archive into a new image.

With a Dockerfile like this:

```Dockerfile
FROM scratch

ADD docker.tar /
```

The image can be build and a container started:

```bash
% docktar /bin/sed
% docker build -t sed .
% docker run --rm sed /bin/sed
Usage: /bin/sed [OPTION]... {script-only-if-no-other-script} [input-file]...
...
```

Note: The Dockerfile example above is the same that is created
with the `-d` switch.

## License

(c) 2017 by Georg Großberger

Licensed under the GPLv3
See the file LICENSE or for details.