Skip to main content

pydocker

Easy generator Dockerfile for humans

Let's use power of python for generate dockerfile!

Advantages:
    - 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

Install

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

Using

# Dockerfile.py
import sys
import logging
import pydocker  # github.com/jen-soft/pydocker

logging.getLogger('').setLevel(logging.INFO)
logging.root.addHandler(logging.StreamHandler(sys.stdout))


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/set_repo.sh', r'''
cp /etc/apt/sources.list /etc/apt/sources.list.copy

cat >/etc/apt/sources.list <<EOL
deb     http://security.debian.org/ jessie/updates main
deb-src http://security.debian.org/ jessie/updates main
deb     http://ftp.nl.debian.org/debian/ jessie main
deb-src http://ftp.nl.debian.org/debian/ jessie main
deb     http://ftp.nl.debian.org/debian/ testing main
EOL

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC
apt-get clean && apt-get update
''')

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

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

d.build_img()
# >_ console:

python3 Dockerfile.py
docker images

Alternative uage:

  • install from repo (without pip)

    F=$(python -c "import site; print(site.getsitepackages()[0]+'/pydocker.py')")
    sudo wget -v -N raw.githubusercontent.com/jen-soft/pydocker/master/pydocker.py -O $F
    
  • without any installation:

    try: from urllib.request import urlopen         # python-3
    except ImportError: from urllib import urlopen  # python-2
    exec(urlopen('https://raw.githubusercontent.com/jen-soft/pydocker/master/pydocker.py').read())
    #
    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 -*-
    try:
        from pydocker import DockerFile  # pip install -U pydocker
    except ImportError:
        try:
            from urllib.request import urlopen         # python-3
        except ImportError:
            from urllib import urlopen  # python-2
        #
        exec(urlopen('https://raw.githubusercontent.com/jen-soft/pydocker/master/pydocker.py').read())
    #
    import sys
    import logging
    
    logging.getLogger('').setLevel(logging.INFO)
    logging.root.addHandler(logging.StreamHandler(sys.stdout))
    
    
    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 Dockerfile.py

License

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

Metadata

Release files for pydocker 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydocker 1.0.6
File Size Uploaded
pydocker-1.0.6.tar.gz 10.8 kB Details

Release files / pydocker-1.0.6.tar.gz

Download URL pydocker-1.0.6.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c3218b19e30c0a8fa18975353a7f7d0739b7db1ea84b92ec1a1fa00296d6419b
BLAKE2b-256 checksum
How to use checksums
d0a0294e917a289cfc45e8b884ef2dbf7ddf7965bc9427fbe04e4e1c5246d7a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.0.6 This release

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page