Coder Social home page Coder Social logo

dockerize's Introduction

Dockerize

Dockerize will pack up your dynamically linked ELF binaries and all their dependencies and turn them into a Docker image.

Some example images built with this tool are available from:

Installation

Dockerize is a standard Python package. You can install it with pip straight from Github like this:

pip install git+https://github.com/larsks/dockerize

Synopsis

usage: dockerize [-h] [--tag TAG] [--cmd CMD] [--entrypoint ENTRYPOINT]
                 [--no-build] [--output-dir OUTPUT_DIR] [--add-file SRC DST]
                 [--symlinks SYMLINKS] [--user USER] [--group GROUP]
                 [--filetools] [--verbose] [--debug] [--version]
                 ...

positional arguments:
  paths

optional arguments:
  -h, --help            show this help message and exit
  --add-file SRC DST, -a SRC DST
                        Add file <src> to image at <dst>
  --symlinks SYMLINKS, -L SYMLINKS
                        One of preserve, copy-unsafe, skip-unsafe, copy-all
  --user USER, -u USER  Add user to /etc/passwd in image
  --group GROUP, -g GROUP
                        Add group to /etc/group in image
  --filetools           Add common file manipulation tools
  --version             show program's version number and exit

Docker options:
  --tag TAG, -t TAG     Tag to apply to Docker image
  --cmd CMD, -c CMD
  --entrypoint ENTRYPOINT, -e ENTRYPOINT

Output options:
  --no-build, -n        Do not build Docker image
  --output-dir OUTPUT_DIR, -o OUTPUT_DIR

Logging options:
  --verbose
  --debug

A simple example

Create a sed image:

dockerize -t sed /bin/sed

Use it:

$ echo hello world | docker run -i sed s/world/jupiter
hello jupiter

A more complicated example

Create an image named thttpd:

dockerize -t thttpd \
  -a /var/www/thttpd /var/www \
  --entrypoint '/usr/sbin/thttpd -D' \
  --cmd '-d /var/www' \
  /usr/sbin/thttpd

Serve default content:

docker run thttpd

Serve your own content:

docker run -v /my/content:/var/www thttpd

dockerize's People

Contributors

berkus avatar brbsix avatar cz172638 avatar elbaro avatar iddm avatar larsks avatar lrsk avatar renzok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dockerize's Issues

dockerize do not recognize dependencies on debian

reproducer:
on debian buster:
install podman from repository mentioned in https://podman.io/getting-started/installation in debian section.

$ apt install python3-jinja2 python3-pyelftools tcpdump
$ pip3 install --user git+https://github.com/larsks/dockerize
$ dockerize -t tcpdump:buster-amd64-latest /usr/sbin/tcpdump
$ podman diff $(podman image list -n localhost/tcpdump:buster-amd64-latest --format "{{.ID}}")
A /Dockerfile
A /etc
A /etc/group
A /etc/nsswitch.conf
A /etc/passwd
A /usr
A /usr/sbin
A /usr/sbin/tcpdump
$ 

Install instructions?

It'd be nice to have instructions in the README for installing dockerize.

EDIT: Preferably, without having to clone the git repository.

AttributeError: 'int' object has no attribute 'isdigit'

I've got this error while trying to run example from README:

$ dockerize -t sed /bin/sed
Traceback (most recent call last):
  File "/home/kvs/.local/bin/dockerize", line 11, in <module>
    sys.exit(main())
  File "/home/kvs/.local/lib/python3.5/site-packages/dockerize/main.py", line 125, in main
    app.build()
  File "/home/kvs/.local/lib/python3.5/site-packages/dockerize/dockerize.py", line 122, in build
    self.resolve_deps()
  File "/home/kvs/.local/lib/python3.5/site-packages/dockerize/dockerize.py", line 200, in resolve_deps
    deps.add(path)
  File "/home/kvs/.local/lib/python3.5/site-packages/dockerize/depsolver.py", line 110, in add
    self.get_deps(path)
  File "/home/kvs/.local/lib/python3.5/site-packages/dockerize/depsolver.py", line 81, in get_deps
    elf = ELFFile(path)
  File "/home/kvs/.local/lib/python3.5/site-packages/dockerize/depsolver.py", line 36, in __init__
    self.read_sections()
  File "/home/kvs/.local/lib/python3.5/site-packages/dockerize/depsolver.py", line 48, in read_sections
    if not line or not line[0].isdigit():
AttributeError: 'int' object has no attribute 'isdigit'

Used version (installed via pip):

$ dockerize --version
dockerize version 0.2.2

[Feature Request]: Add ability to pass environment variables

I am wondering if it is possible to pass environment variables at the time of creation.

To push it further, would it make sense to support this tool as an extension in Dockerfile.
Ex:
DOCKERIZE [/path/to/the/binary1,/path/to/the/binary2,...]

The above would allow simply build the lean docker image with existing workflow thus broader reach.

support podman/buildah beside docker

docker command is hardcoded.
with symlink docker -> podman i was able to create container with rootless approach (see #22 ).
with option -T (as -t is already used) or similar we should be able to select which container engine/runtime to use.

nice to haves

  • -a flag with only one entry simply mirrors the folder
  • read lists from file for files/binaries/users

Error when trying to dockerize

Hi there,

when I run dockerize I get the following:

$ dockerize dockerize -t php /Users/me/source/local/php-lxc/build/php-5.6.18/usr/local/php/bin
Traceback (most recent call last):
  File "/usr/local/bin/dockerize", line 9, in <module>
    load_entry_point('dockerize==0.2', 'console_scripts', 'dockerize')()
  File "build/bdist.macosx-10.11-x86_64/egg/dockerize/main.py", line 117, in main
  File "build/bdist.macosx-10.11-x86_64/egg/dockerize/dockerize.py", line 89, in add_file
ValueError: dockerize: container paths must be fully qualified

dockerize a python pip dependency.

I'm trying to install scipy but it takes too much time to compile, is there a way to do that using dockerize.

Dockerfile
FROM gliderlabs/alpine:3.4

RUN apk add --no-cache
ca-certificates
python-dev
libstdc++
libgfortran
&& apk add --no-cache --virtual=build_dependencies
gfortran
g++
make
&& ln -s /usr/include/locale.h /usr/include/xlocale.h
&& mkdir -p /tmp/build
&& cd /tmp/build/
&& wget http://www.netlib.org/blas/blas-3.6.0.tgz
&& wget http://www.netlib.org/lapack/lapack-3.6.1.tgz
&& tar xzf blas-3.6.0.tgz
&& tar xzf lapack-3.6.1.tgz
&& cd /tmp/build/BLAS-3.6.0/
&& gfortran -O3 -std=legacy -m64 -fno-second-underscore -fPIC -c .f
&& ar r libfblas.a *.o
&& ranlib libfblas.a
&& mv libfblas.a /tmp/build/.
&& cd /tmp/build/lapack-3.6.1/
&& sed -e "s/frecursive/fPIC/g" -e "s/ ..// /g" -e "s/^CBLASLIB/#CBLASLIB/g" make.inc.example > make.inc
&& make lapacklib
&& make clean
&& mv liblapack.a /tmp/build/.
&& cd /
&& export BLAS=/tmp/build/libfblas.a
&& export LAPACK=/tmp/build/liblapack.a
&& python -m pip --no-cache-dir install pip -U
&& python -m pip --no-cache-dir install scipy
&& apk del --purge -r build_dependencies
# && rm -rf /tmp/build
# && rm -rf /var/cache/apk/

Solved runtime dependencies

Hey there, a while back when I used your tool to try to get PHP standalone, I ran into the problem of resolving runtime dependencies.

Here is my solution to that https://github.com/mozzymoz/packager
I'm no python wizard, that is why I didn't make a PR, but could be sometime you might be interested in

Workingdir

I think that the default working dir of the image dockerize create is '/', can we add an optional argument like

`optional arguments:
-w, --wd change the working dir

And then, in the dockerfile

`FROM scratch
COPY . /
WORKDIR /home/great/music/

ENTRYPOINT ["/bin/bash"]
`
Thanks in advance

Open Source Licenses?

Hi Lars,

It is really cool that you are producing so many open source tools. I don't see any license with them, however, so it will limit how much the code can be used in other projects. Could you add an open source license, perhaps Berkeley Three Clause or Public Domain, which are very compatible with open source projects? Take a look at these pages for information about selecting and including copyright and license statements.

https://www.jeffknupp.com/blog/2013/08/16/open-sourcing-a-python-project-the-right-way/
http://www.groklaw.net/article.php?story=20031231092027900
http://www.pydanny.com/cookie-project-templates-made-easy.html
https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29

Thanks again and keep up the good work!

Dave

Does not work on Windows

The application attempts to import the grp module which obviously isn't going to fly on Windows. Please clarify what platforms this is supposed to run on in the README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.