Introduction
Have you worked on the deployment of complex IT Systems? Have you ever worked on the automation of the configuration of IT Systems?

This article focuses on one of the automation engines, i.e., Salt Project. We will study the Salt States and Commands in detail. We will try to understand how to use the Salt states and the Salt States inside the Docker container as well.
Salt States and Commands in Docker Container
The Salt version 2016.11.0 was an essential update in the Salt.
-
It introduced the feature of executing Salt States. It also provides the feature of Salt remote execution commands which can be done directly inside the container of the Docker.
-
With this addition, you can now use the Salt States to deploy containers other than new ones. This feature allows Salt to audit and modify running containers without having to run a Salt Minion within the container. It has many applications, like getting operating data from containers and doing security audits on active containers.
-
This feature is quite simple and straightforward. You can use this feature using a running Salt Minion, Salt SSH, or the Salt Call Command. In this article, we will use the Salt Call command. This is because you can translate all the salt commands directly to salt-ssh and salt.
Now, let's see how to use this feature in more detail.
Step 1 - Installation of Docker
The first step is crucial step when you want to work on Docker. You will have to install Docker to use its features. You can download the setup from the official site. After the proper download, you can install it.
After the complete installation, you must have the docker-py library as well. You must have the docker-py library in case you want to work with the Docker Integration. You can do it by using pip or using your system package manager. You can use the following command:
pip install docker-py
Step 2 - Installation of Salt
The next is also the most crucial step. The second step is to download and install the Salt.
We will work with the Salt Call. The Salt Call is available in the salt-minion package of salt.
Step 3 - Creation using Salt States
In the third step, we will work with the Salt states, and for that, we will need them.
For example, here, we can use a very basic state which will be responsible for the installation of vim.
We can do anything that the Salt states can do.
Let's try to understand this with an example.
In this example, we will simply create a small state file first. You must create this file in /srv/salt/vim.sls.
The next step is to run the docker.sls_build command. For this, execute the following command:
salt-call --local dockerng.sls_build test_cn base=my_base_image mods=vim
After the above steps, we will have a fresh image named test_cn. We can work with this image. And vim has been installed.
Step 4 - Executing Command in the Container
Now, you can use Salt to run the remote execution functions. You can use these functions in the container. In case you want to run the function, you can use a different simple salt-call command. You can use the following commands:
salt-call --local dockerng.call test_cn test_cn.version
salt-call --local dockerng.call test_cn network.interfaces
salt-call --local dockerng.call test_cn disk.usage
salt-call --local dockerng.call test_cn pkg.list_pkgs
salt-call --local dockerng.call test_cn service.running httpd
salt-call --local dockerng.call test_cn cmd.run 'ls -l /etc'