In our previous article https://linuxnotes.org/salt-run-command-on-docker-container/. We’ve described how to run simple command in the docker container with salt. This article will show hot to start and run multiple commands in docker using the docker.running the salt command. Let’s start.
How docker.running works
Docker.running ensures that a container with a specific configuration is present and running. Flags which can be used for container start:
Name of the container.
Image to use for the container.
The network’s argument can be used to ensure that a container is attached to one or more networks. Optionally, arguments can be passed to the networks. In the example below, net1 is being configured with arguments, while net2 and bridge are being configured without arguments.
List of DNS nameservers. Which you can express as a comma-separated list or a YAML list.
port_bindings (or publish)
Bind exposed ports. Port bindings should be passed in the same way as the –publish argument to the docker run CLI command:
ip:hostPort:containerPort – will bind a specific IP and port on the host to be a specific port within the container.
ip::containerPort – binds a specific IP and an ephemeral port to a specific port within the container.
hostPort:containerPort – Bind a specific port on all of the host’s interfaces to a specific port within the container.
containerPort – Bind an ephemeral port on all of the host’s interfaces to a specific port within the container.
You can use Multiple bindings separated by commas or expressed as a YAML list, and port ranges can be defined using dashes.
Example of docker.running salt state
– name: nodejs-build
– image: nodejs:latest
– binds: /home/myuser/nodejs:/var/www/nodejs
– replace: True
– working_dir: /var/www/nodejs
– dns: 188.8.131.52
It’s a basic example how to use docker.running salt state. You can read more usage by the link in official documentation: https://docs.saltstack.com/en/latest/ref/states/all/salt.states.docker_container.html#salt.states.docker_container.running
You can find more salt manuals https://linuxnotes.org/category/salt-manuals/
Viva La Linux!