wishi
wishi

Reputation: 7387

How do I run a salt state on a running docker container

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

Upvotes: 0

Views: 1446

Answers (1)

Roald Nefs
Roald Nefs

Reputation: 1412

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.

Upvotes: 1

Related Questions