1
0

docker_sls.rst 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. .. _docker-sls:
  2. =====================================================
  3. Running Salt States and Commands in Docker Containers
  4. =====================================================
  5. The 2016.11.0 release of Salt introduces the ability to execute Salt States
  6. and Salt remote execution commands directly inside of Docker containers.
  7. This addition makes it possible to not only deploy fresh containers using
  8. Salt States. This also allows for running containers to be audited and
  9. modified using Salt, but without running a Salt Minion inside the container.
  10. Some of the applications include security audits of running containers as
  11. well as gathering operating data from containers.
  12. This new feature is simple and straightforward, and can be used via a running
  13. Salt Minion, the Salt Call command, or via Salt SSH. For this tutorial we will
  14. use the `salt-call` command, but like all salt commands these calls are
  15. directly translatable to `salt` and `salt-ssh`.
  16. Step 1 - Install Docker
  17. =======================
  18. Since setting up Docker is well covered in the Docker documentation we will
  19. make no such effort to describe it here. Please see the Docker Installation
  20. Documentation for installing and setting up Docker:
  21. https://docs.docker.com/engine/installation/
  22. The Docker integration also requires that the `docker-py` library is installed.
  23. This can easily be done using pip or via your system package manager:
  24. .. code-block:: bash
  25. pip install docker-py
  26. Step 2 - Install Salt
  27. =====================
  28. For this tutorial we will be using Salt Call, which is available in the
  29. `salt-minion` package, please follow the Salt Installation docs found here:
  30. https://repo.saltstack.com/
  31. Step 3 - Create With Salt States
  32. ================================
  33. Next some Salt States are needed, for this example a very basic state which
  34. installs `vim` is used, but anything Salt States can do can be done here,
  35. please see the Salt States Introduction Tutorial to learn more about Salt
  36. States:
  37. https://docs.saltstack.com/en/stage/getstarted/config/
  38. For this tutorial, simply create a small state file in `/srv/salt/vim.sls`:
  39. .. code-block:: yaml
  40. vim:
  41. pkg.installed
  42. .. note::
  43. The base image you choose will need to have python 2.6 or 2.7 installed.
  44. We are hoping to resolve this constraint in a future release.
  45. If `base` is omitted the default image used is a minimal openSUSE
  46. image with Python support, maintained by SUSE
  47. Next run the `docker.sls_build` command:
  48. .. code-block:: bash
  49. salt-call --local dockerng.sls_build test base=my_base_image mods=vim
  50. Now we have a fresh image called `test` to work with and vim has been
  51. installed.
  52. Step 4 - Running Commands Inside the Container
  53. ==============================================
  54. Salt can now run remote execution functions inside the container with another
  55. simple `salt-call` command:
  56. .. code-block:: bash
  57. salt-call --local dockerng.call test test.version
  58. salt-call --local dockerng.call test network.interfaces
  59. salt-call --local dockerng.call test disk.usage
  60. salt-call --local dockerng.call test pkg.list_pkgs
  61. salt-call --local dockerng.call test service.running httpd
  62. salt-call --local dockerng.call test cmd.run 'ls -l /etc'