Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/jen-soft/pydocker

Easy generator Dockerfile for humans
https://github.com/jen-soft/pydocker

deploy docker docker-image dockerfile for-humans pydocker python

Last synced: 4 days ago
JSON representation

Easy generator Dockerfile for humans

Awesome Lists containing this project

README

        

# 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

```python
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'''
```
```bash
cp /etc/apt/sources.list /etc/apt/sources.list.copy

cat >/etc/apt/sources.list <_ console:

python3 Dockerfile.py
docker images
```

## Alternative uage:
- install from repo (without pip)
```bahs
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:
```python
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
```python
#!/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.