RUNNING SALT STATES AND COMMANDS IN DOCKER CONTAINERS - Salt management using container docker

RUNNING SALT STATES AND COMMANDS IN DOCKER CONTAINERS

Salt 2016.11.0 release introduces the ability to perform Salt States and Salt remote execution of commands directly in the Docker containers.

This feature not only allows use Salt States to deploy a new container, also allows the use of Salt on the running of container do review and modify, but do not need to run the Salt Minion in the container. Some scenarios include safety audits run container and container operations from collecting data.

This new feature is simple, can be used by Salt Minion a running, Salt Call command or Salt SSH. For this tutorial, we will use the salt-call command, but like all salt command, these calls can be directly converted into salt and salt-ssh.

STEP 1 - INSTALL DOCKER

Since Docker document good introduction to Docker settings, so we will not be described here. For information on installation and setup Docker, see the installation documentation Docker: https://docs.docker.com/engine/installation/

Docker integrated functional support also requires the installation of docker-py library. This can be done through pip or system package manager easy to complete:

pip install docker-py

STEP 2 - INSTALL SALT

In this tutorial, we will use the Salt Call package provided salt-minion, follow the Salt Installation documentation here: https://repo.saltstack.com/

STEP 3 - CREATE WITH SALT STATES

Next we need to define some Salt state, for example, a very simple installation using state vim, but nothing Salt States can do can be done here, see Salt States Introduction Tutorial to learn more about the Salt States information: https://docs.saltstack.com/en/stage/getstarted/config/

In this tutorial, simply create a small file in the state in /srv/salt/vim.sls:

vim:
  pkg.installed

Note: You select a container base image management needs to have installed python 2.6 or 2.7. We hope to resolve this constraint in future releases.

If omitted, the default image base, they are using the image having the minimum openSUSE supported Python, maintained by SUSE

Next, run docker.sls_build command:

salt-call --local dockerng.sls_build test base=my_base_image mods=vim

Now we have a test container called, and the vim installed.

STEP 4 - RUNNING COMMANDS INSIDE THE CONTAINER

Salt can now use other simple salt-call command to run the remote execution function of the container:

salt-call --local dockerng.call test test.version
salt-call --local dockerng.call test network.interfaces
salt-call --local dockerng.call test disk.usage
salt-call --local dockerng.call test pkg.list_pkgs
salt-call --local dockerng.call test service.running httpd
salt-call --local dockerng.call test cmd.run 'ls -l /etc'

Guess you like

Origin blog.csdn.net/watermelonbig/article/details/93843162