0

Is there any way to run a shell command as part of a Salt state inside of a running docker container? I find the whole dockerng module in Salt very confusing, because it only lists ad hoc commands.

From what I can grasp from the docs it should work like this:

mystate:
    dockerng.run:
      - name: 12345
      - cmd: bash -l -c ifconfig

That doesn't seem to be the case.

The command on the master:

 sudo salt-ssh -i box_with_docker_containers state.apply

The error:

State 'dockerng.run' was not found in SLS

wishi
  • 7,188
  • 17
  • 64
  • 103
  • 1
    Do you mean dockerng.running instead of dockerng.run ? https://docs.saltstack.com/en/latest/ref/states/all/salt.states.dockerng.html#salt.states.dockerng.running – Mostafa Hussein Oct 20 '16 at 14:34
  • No, the container is started and up. I can attach to it, and run a bash command. That's what I want Salt to do. – wishi Oct 20 '16 at 16:46
  • 1
    `dockerng` has no `run` function, you can use `dockerio.run` to run a command inside a container https://docs.saltstack.com/en/latest/ref/states/all/salt.states.dockerio.html#salt.states.dockerio.run – Mostafa Hussein Oct 20 '16 at 22:17

1 Answers1

1

The dockerng.run module:

The dockerng modules includes a run function:

mystate:
  module.run:
    - name: dockerng.run
    - m_name: 12345
    - cmd: bash -l -c ifconfig

The name is the name of the module, m_name the container name or ID in which to run the command and cmd is the command.

See the salt.modules.dockerng documentation for more information about the dockerng module.

See salt.states.module for more information about running modules from within a state.

The deprecated dockerio.run state:

Using the dockerio.run you can run a command in a specific container:

mystate:
  dockerio.run:
    - name: bash -l -c ifconfig
    - cid: 12345

The name is the command to run in the container and the cid the Container id or name.

Note that the dockerio is deprecated since version 2015.8.0, future feature development will be done only in dockerng.

Roald Nefs
  • 1,302
  • 10
  • 29