• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language SaltStack
  • License
    Other
  • Created about 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Install and set up Docker

docker-formula

Extensible formula to manage Docker on MacOS, Windows, and GNU/Linux. Currently supports:

The default docker.software and docker.compose.software states support:

The other states support container managmement.

Travis CI Build Status Semantic Release

A SaltStack formula for Docker on MacOS, GNU/Linux, Windows and Raspberry Pi (4b).

General notes

See the full SaltStack Formulas installation and usage instructions. If you are interested in writing or contributing to formulas, please pay attention to the Writing Formula Section. If you want to use this formula, please pay attention to the FORMULA file and/or git tag, which contains the currently released version. This formula is versioned according to Semantic Versioning. See Formula Versioning Section for more details.

Contributing to this repo

Commit message formatting is significant!!

Please see How to contribute for more details.

Available Meta states

docker

Meta-state (This is a state that includes other states).

This state installs the Docker solution (see https://docs.docker.io) for Raspberry Pi support please see Notes

docker.clean

Meta-state (This is a state that includes other states).

Stop Docker daemon and remove docker packages ('docker', 'docker-engine', 'docker-ce', etc) on Linux. To protect OS integrity, this state won't remove packages listed as dependencies (i.e. python is kept).

docker.software.package.repo

Configures the upstream Docker's repo on RedHat/Debian OS.

docker.software.package.repo.clean

This state removes upstream Docker package repository only, on RedHat/Debian OS.

docker.software

This state installs Docker (see https://docs.docker.com/engine/install and https://docs.docker.com/desktop/)

docker.software.service

This state installs Dockerd daemon on Linux (systemd support).

docker.software.service.clean

This state stops Dockerd daemon on Linux (systemd support).

docker.software.config

This state overrides default Docker options (i.e. /etc/default/docker):

docker:
  pkg:
    docker:
      config:
        - DOCKER_OPTS="-s btrfs --dns 8.8.8.8"
        - export http_proxy="http://172.17.42.1:3128"

docker.software.config.clean

This state uninstalls Docker overrides (i.e. /etc/default/docker).

docker.software.clean

This state uninstalls Docker software.

docker.containers

Pulls and runs a number of docker containers. See docker container API for docker.containers options:

docker:
  containers:
    running:
      - prometheus_simple
      - prometheus_detail

    prometheus_simple:
      image: "prom/prometheus:v1.7.1"

    prometheus_detail:
      image: "prom/prometheus:v1.7.1"
      # see https://docker-py.readthedocs.io/en/stable/containers.html

docker.compose

Saltstack dockercompose module state support (See https://docs.saltstack.com/en/2018.3/ref/modules/all/salt.modules.dockercompose.html).

docker.compose.ng

The intent is to provide an interface similar to the specification provided by docker-compose. The hope is that you may provide pillar data similar to that which you would use to define services with docker-compose. The assumption is that you are already using pillar data and salt formulae to represent the state of your existing infrastructure.

No real effort had been made to support every possible feature of docker-compose. Rather, we prefer the syntax provided by the docker-compose whenever it is reasonable for the sake of simplicity.

It is worth noting that we have added one attribute which is decidedly absent from the docker-compose specification. That attribute is dvc. This is a boolean attribute which allows us to define data only volume containers which can not be represented with the docker.software.service.running state since they are not intended to include a long living service inside the container.

See the included pillar.example for a representative pillar data block. To use this formula, you might target a host with the following pillar:

docker:
  compose:
    ng:
      registry-datastore:
        dvc: true
        # image: &registry_image 'docker.io/registry:latest' ## Fedora
        image: &registry_image 'registry:latest'
        container_name: &dvc 'registry-datastore'
        command: echo *dvc data volume container
        volumes:
          - &datapath '/registry'
      registry-service:
        image: *registry_image
        container_name: 'registry-service'
        volumes_from:
          - *dvc
        environment:
          SETTINGS_FLAVOR: 'local'
          STORAGE_PATH: *datapath
          SEARCH_BACKEND: 'sqlalchemy'
          REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: '/registry'
        ports:
          - 127.0.0.1:5000:5000
        # restart: 'always'    # compose v1.9
        deploy:                # compose v3
          restart_policy:
            condition: on-failure
            delay: 5s
            max_attempts: 3
            window: 120s
      nginx-latest:
        # image: 'docker.io/nginx:latest'  ##Fedora
        image: 'nginx:latest'
        container_name: 'nginx-latest'
        links:
          - 'registry-service:registry'
        ports:
          - '80:80'
          - '443:443'
        volumes:
          - /srv/docker-registry/nginx/:/etc/nginx/conf.d
          - /srv/docker-registry/auth/:/etc/nginx/conf.d/auth
          - /srv/docker-registry/certs/:/etc/nginx/conf.d/certs
        working_dir: '/var/www/html'
        volume_driver: 'local'
        userns_mode: 'host'

Then you would target a host with the following states:

include:
  - base: docker
  - base: docker.compose.ng

docker.swarm

Saltstack swarm module state support (See https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.swarm.html).

docker.swarm.clean

Opposite of docker.swarm state (See https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.swarm.html).

docker.networks

Create docker networks

docker.networks.clean

Remove docker networks

Sub-states

Sub-states are available inside sub-directories.

Notes on Raspberry Pi support

There are some caveats with regard to the support of this module on Rasberry Pi 4b's.

  • This module has only been tested with Raspberry Pi 4b using Rasbian Os Version Buster
  • This module supports raspbian only when used from Salt 3002.6. Salt 3003.x fails with template isses.
  • Docker service is known to fail starting when freshly installed via this module on Rasbian Buster with all apt-get updates and upgrades performed. The error found in logs for failing to start is dockerd: failed to create NAT chain DOCKER

The Reason for this is as documented here . The following Fix followed by a restart fixes this. The summary reason is that the docker installer uses iptables for nat. Unfortunately Debian uses nftables. You can convert the entries over to nftables or just setup Debian to use the legacy iptables. On the target Raspberry Pi issue the following to resolve or incorporate the SLS before in your custom SLS

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
sudo shutdown -r 0  # Do a restart, Docker.d should then function

or the following SLS

iptables:
  alternatives.set:
    - path:  /usr/sbin/iptables-legacy
ip6tables:
  alternatives.set:
    - path:  /usr/sbin/ip6tables-legacy

The provisioning of docker to raspbian uses functionality from https://docs.docker.com/engine/install/debian/#install-using-the-convenience-script. It specifically mentions Using these scripts is not recommended for production environments, and you should understand the potential risks before you use them: The reasons are stated as :

  • The scripts require root or sudo privileges to run. Therefore, you should carefully examine and audit the scripts before running them.
  • The scripts attempt to detect your Linux distribution and version and configure your package management system for you. In addition, the scripts do not allow you to customize any installation parameters. This may lead to an unsupported configuration, either from Docker’s point of view or from your own organization’s guidelines and standards.
  • The scripts install all dependencies and recommendations of the package manager without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.
  • The script does not provide options to specify which version of Docker to install, and installs the latest version that is released in the β€œedge” channel.
  • Do not use the convenience script if Docker has already been installed on the host machine using another mechanism.

Testing

Linux testing is done with kitchen-salt.

Requirements

  • Ruby
  • Docker
$ gem install bundler
$ bundle install
$ bin/kitchen test [platform]

Where [platform] is the platform name defined in kitchen.yml, e.g. debian-9-2019-2-py3.

bin/kitchen converge

Creates the Docker instance and runs the docker main state, ready for testing.

bin/kitchen verify

Runs the inspec tests on the actual instance.

bin/kitchen destroy

Removes the Docker instance.

bin/kitchen test

Runs all of the stages above in one go: i.e. destroy + converge + verify + destroy.

bin/kitchen login

Gives you SSH access to the instance for manual testing.

More Repositories

1

salt-formula

Yes, Salt can Salt itself!
SaltStack
193
star
2

nginx-formula

Nginx Salt Formula
SaltStack
163
star
3

template-formula

SaltStack formula template filled with dummy content
Jinja
116
star
4

users-formula

Configure users via pillar
SaltStack
98
star
5

openssh-formula

Jinja
90
star
6

mysql-formula

Install the MySQL client and/or server
SaltStack
81
star
7

ec2-autoscale-reactor

Autonomous Minion Management via EC2 Autoscaler
SaltStack
77
star
8

postgres-formula

SaltStack
75
star
9

php-formula

Jinja
57
star
10

zabbix-formula

Jinja
51
star
11

apache-formula

Set up and configure the Apache HTTP server
Jinja
49
star
12

django-formula

Python
42
star
13

jenkins-formula

SaltStack
42
star
14

os-hardening-formula

SaltStack
41
star
15

redis-formula

Redis state
Jinja
40
star
16

fail2ban-formula

SaltStack
40
star
17

sudoers-formula

Ruby
40
star
18

salt-cloud-reactor

Autonomous Minion Management via Salt Cloud
SaltStack
38
star
19

hadoop-formula

SaltStack
37
star
20

openvpn-formula

Setup and configure openvpn server and client.
Jinja
34
star
21

hostsfile-formula

Use minion IDs to keep /etc/hosts and hostnames consistent for clusters without DNS
Ruby
32
star
22

gitlab-formula

SaltStack
31
star
23

mongodb-formula

SaltStack
31
star
24

vim-formula

Trick out vim
Vim Script
31
star
25

iptables-formula

SaltStack
31
star
26

bind-formula

Ruby
30
star
27

prometheus-formula

Manage a Prometheus installation
SaltStack
27
star
28

haproxy-formula

Jinja
27
star
29

zookeeper-formula

Jinja
27
star
30

node-formula

Manage node.js with SaltStack
SaltStack
26
star
31

postfix-formula

Ruby
26
star
32

logstash-formula

SaltStack
24
star
33

sun-java-formula

Flexible provisioning for JDK and JRE tarballs
SaltStack
24
star
34

epel-formula

Install the EPEL RPM and GPG key
Ruby
23
star
35

ntp-formula

Ruby
23
star
36

systemd-formula

SaltStack
23
star
37

consul-formula

Formula to install and configure Hashicorp Consul
Jinja
23
star
38

logrotate-formula

Ruby
22
star
39

rabbitmq-formula

SaltStack
22
star
40

nagios-formula

nagios-formula
SaltStack
22
star
41

openstack-standalone-formula

Single Server OpenStack
SaltStack
22
star
42

lxd-formula

Python
21
star
43

elasticsearch-formula

SaltStack
21
star
44

collectd-formula

SaltStack
20
star
45

kubernetes-formula

Salt formula to manage kubernetes
SaltStack
20
star
46

aptly-formula

SaltStack
18
star
47

libvirt-formula

Jinja
18
star
48

sysctl-formula

Saltstack sysctl formula,
Ruby
18
star
49

icinga2-formula

SaltStack
18
star
50

snmp-formula

Ruby
17
star
51

nfs-formula

Ruby
17
star
52

samba-formula

Jinja
17
star
53

tomcat-formula

Ruby
16
star
54

graphite-formula

SaltStack
16
star
55

vault-formula

Ruby
15
star
56

git-formula

SaltStack
14
star
57

syslog-ng-formula

Jinja
14
star
58

memcached-formula

SaltStack
14
star
59

vmware-tools-formula

SaltStack
13
star
60

ceph-formula

HTML
13
star
61

virtualenv-formula

SaltStack
11
star
62

resolver-formula

SaltStack
11
star
63

openldap-formula

Ruby
11
star
64

packages-formula

A simple 'packages manager' formula, to install/remove packages without further ado.
SaltStack
11
star
65

java-formula

Jinja
11
star
66

tinc-formula

tinc formula
Shell
11
star
67

tmux-formula

HTML
11
star
68

grafana-formula

Manage Grafana via Salt
SaltStack
10
star
69

squid-formula

Ruby
10
star
70

openvpn-client-formula

A saltstack formula for pushing keys and config to openvpn clients.
SaltStack
9
star
71

reverse-users-formula

9
star
72

uwsgi-formula

Salt formula to manage uwsgi
SaltStack
9
star
73

kafka-formula

SaltStack
8
star
74

screen-formula

SaltStack
8
star
75

python2-formula

SaltStack
8
star
76

dhcpd-formula

Ruby
8
star
77

dnsmasq-formula

Ruby
8
star
78

pip-formula

SaltStack
7
star
79

backuptocloud-formula

http://docs.saltstack.com/topics/conventions/formulas.html
SaltStack
7
star
80

opendkim-formula

Salt-Stack formula for opendkim
SaltStack
7
star
81

cloudstack-formula

SaltStack
7
star
82

hosts-formula

Manage your hosts file
Python
7
star
83

munin-formula

Saltstack formula for munin and munin-node
SaltStack
7
star
84

newrelic-formula

SaltStack
7
star
85

piwik-formula

SaltStack
7
star
86

beaver-formula

Shell
7
star
87

owncloud-formula

SaltStack
7
star
88

nexus-formula

Provision Sonatype Nexus with Saltstack
Shell
7
star
89

crontab-formula

saltstack formula to manage crontab
HTML
6
star
90

wireguard-formula

Manages wireguard installations
Jinja
6
star
91

dovecot-formula

SaltStack
6
star
92

varnish-formula

SaltStack
6
star
93

mounts-formula

SaltStack formula for managing mounts
SaltStack
6
star
94

bareos-formula

A Saltstack formula to install and configure Bareos
SaltStack
5
star
95

linux-dev-formula

Development files for linux
Scheme
5
star
96

nano-formula

Scheme
5
star
97

eramba-formula

Scheme
5
star
98

mediawiki-formula

MediaWiki
PHP
5
star
99

reverse-grains-formula

SaltStack
5
star
100

ruby-formula

SaltStack
5
star