Docker is a lightweight, portable, self-sufficient software container wrapper. The base supported wrapper type is LXC, cgroups, and the Linux Kernel.
Warning
This state module is beta. The API is subject to change. No promise as to performance or functionality is yet present.
Note
This state module requires docker-py which supports Docker Remote API version 1.6.
built
corp/mysuperdocker_img:
docker.built:
- path: /path/to/dir/container
pulled
ubuntu:
docker.pulled:
- tag: latest
pushed
corp/mysuperdocker_img:
docker.pushed
installed
mysuperdocker-container:
docker.installed:
- name: mysuperdocker
- hostname: superdocker
- image: corp/mysuperdocker_img
running
my_service:
docker.running:
- container: mysuperdocker
- port_bindings:
"5000/tcp":
HostIp: ""
HostPort: "5000"
Note
The port_bindings
argument above is a dictionary. Note the
double-indentation, this is required for PyYAML to load the data
structure properly as a dictionary. More information can be found
here
absent
mys_old_uperdocker:
docker.absent
run
/finish-install.sh:
docker.run:
- cid: mysuperdocker
- unless: grep -q something /var/log/foo
- docker_unless: grep -q done /install_log
Note
The docker modules are named dockerio
because
the name 'docker' would conflict with the underlying docker-py library.
We should add magic to all methods to also match containers by name now that the 'naming link' stuff has been merged in docker. This applies for example to:
salt.states.dockerio.
absent
(name)¶Ensure that the container is absent; if not, it will will be killed and destroyed. (docker inspect)
salt.states.dockerio.
built
(name, path=None, quiet=False, nocache=False, rm=True, force=False, timeout=None, *args, **kwargs)¶Build a docker image from a path or URL to a dockerfile. (docker build)
salt.states.dockerio.
installed
(name, image, command=None, hostname=None, user=None, detach=True, stdin_open=False, tty=False, mem_limit=0, ports=None, environment=None, dns=None, volumes=None, volumes_from=None, *args, **kwargs)¶Ensure that a container with the given name exists; if not, build a new container from the specified image. (docker run)
For other parameters, see absolutely first the salt.modules.dockerio execution module and the docker-py python bindings for docker documentation <https://github.com/dotcloud/docker-py#api>`_ for docker.create_container.
Note
This command does not verify that the named container is running the specified image.
salt.states.dockerio.
mod_watch
(name, sfun=None, *args, **kw)¶salt.states.dockerio.
present
(name)¶If a container with the given name is not present, this state will fail. (docker inspect)
salt.states.dockerio.
pulled
(name, tag='latest', force=False, *args, **kwargs)¶Pull an image from a docker registry. (docker pull)
Note
See first the documentation for docker login, docker pull, docker push, and docker.import_image (docker import). NOTE that we added in SaltStack a way to authenticate yourself with the Docker Hub Registry by supplying your credentials (username, email & password) using pillars. For more information, see salt.modules.dockerio execution module.
salt.states.dockerio.
pushed
(name, tag='latest')¶Push an image from a docker registry. (docker push)
Note
See first the documentation for docker login, docker pull, docker push, and docker.import_image (docker import). NOTE that we added in SaltStack a way to authenticate yourself with the Docker Hub Registry by supplying your credentials (username, email & password) using pillars. For more information, see salt.modules.dockerio execution module.
salt.states.dockerio.
run
(name, cid=None, hostname=None, onlyif=None, unless=None, docked_onlyif=None, docked_unless=None, *args, **kwargs)¶Run a command in a specific container
You can match by either name or hostname
salt.states.dockerio.
running
(name, container=None, port_bindings=None, binds=None, publish_all_ports=False, links=None, lxc_conf=None, privileged=False, dns=None, volumes_from=None, network_mode=None, restart_policy=None, cap_add=None, cap_drop=None, check_is_running=True)¶Ensure that a container is running. (docker inspect)
publish_all_ports
Link several container together
- links:
name_other_container: alias_for_other_container
- port_bindings:
"5000/tcp":
HostIp: ""
HostPort: "5000"
List of volumes to mount (like -v
of docker run
command),
mapping host directory to container directory.
For read-write mounting, use the short form:
- binds:
/var/log/service: /var/log/service
Or, to specify read-only mounting, use the extended form:
- binds:
/home/user1:
bind: /mnt/vol2
ro: true
/var/www:
bind: /mnt/vol1
ro: false
List of DNS servers.
- dns:
- 127.0.0.1
List of container names to get volumes definition from
- volumes_from:
- name_other_container
- network_mode: host
Restart policy to apply when a container exits (no, on-failure[:max-retry], always)
- restart_policy:
MaximumRetryCount: 5
Name: on-failure
salt.states.dockerio.
script
(*args, **kw)¶Placeholder function for a cmd.script alike.
Note
Not yet implemented.
Its implementation might be very similar from
salt.states.dockerio.run