Skip to main content

Easy generator Dockerfile for humans.

Project description

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.

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 details)

Uploaded Source

File details

Details for the file pydocker-1.0.6.tar.gz.

File metadata

  • Download URL: pydocker-1.0.6.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pydocker-1.0.6.tar.gz
Algorithm Hash digest
SHA256 c3218b19e30c0a8fa18975353a7f7d0739b7db1ea84b92ec1a1fa00296d6419b
MD5 493281493201708931ae109e195deb30
BLAKE2b-256 d0a0294e917a289cfc45e8b884ef2dbf7ddf7965bc9427fbe04e4e1c5246d7a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page