Skip to main content

Easy generator Dockerfile for humans.

Project description


Easy generator Dockerfile for humans

Let's use power of python for generate dockerfile!

    - all features from python: variables, multiline strings, code reuse.
    - keep all your code in one file [bash, python, conf, ...]
    - generate many docker files from one template [testing, production, ]
    - generate sequence [Dockerfile.debian => Dockerfile.python => Dockefile.yourapp, ...]
    - or if you not expert in sed, awk - you can use python for modify conf files : )

easy code, easy costomize


# sudo apt-get install python-setuptools && sudo easy_install pip
pip install -U pydocker


import sys
import logging
import pydocker  #


class DockerFile(pydocker.DockerFile):
    """   add here your custom features   """

d = DockerFile(base_img='debian:8.2', name='jen-soft/custom-debian:8.2')

d.RUN_bash_script('/opt/', r'''
cp /etc/apt/sources.list /etc/apt/sources.list.copy

cat >/etc/apt/sources.list <<EOL
deb jessie/updates main
deb-src jessie/updates main
deb jessie main
deb-src jessie main
deb testing main

apt-key adv --keyserver --recv-keys 04EE7237B7D453EC
apt-get clean && apt-get update

d.EXPOSE = 80
d.WORKDIR = '/opt'

# d.ENTRYPOINT = ["/opt/www-data/"]
d.CMD = ["python", "--version"]

# >_ console:

docker images

Alternative uage:

  • install from repo (without pip)

    F=$(python -c "import site; print(site.getsitepackages()[0]+'/')")
    sudo wget -v -N -O $F
  • without any installation:

    try: from urllib.request import urlopen         # python-3
    except ImportError: from urllib import urlopen  # python-2
    d = DockerFile(base_img='debian:8.2', name='jen-soft/custom-debian:8.2')
    # ...
    • Helpful if you need just build img
  • not required installation

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
        from pydocker import DockerFile  # pip install -U pydocker
    except ImportError:
            from urllib.request import urlopen         # python-3
        except ImportError:
            from urllib import urlopen  # python-2
    import sys
    import logging
    class MyDockerFile(DockerFile):
        """   add here your custom features   """
    d = MyDockerFile(base_img='debian:8.2', name='jen-soft/debian:8.2')
    # ...
    • Helpful if you need share your


This work is dual-licensed under Apache License 2.0 <ins>and</ins> MIT License. <ins>You can choose</ins> between one of them if you use this work.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydocker-1.0.6.tar.gz (10.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page