Search code examples
dockersalt-project

Correct way to mount a host directory in a docker container using salt


Using the command line below:

docker run -ti -v /hostDirectory:/containerDirectory

I can map a directory on the host to a directory on the container.

How do I get the same effect using saltstack's dockerng? I don't see anywhere in the documentation referencing the host volume directory mapping to a directory on the container, it looks like dockerng only supports volumes created using docker.


Solution

  • The relevant parameter in dockerng was renamed to 'binds' under the dockerng.running function

    binds
    Files/directories to bind mount. Each bind mount should be passed in the format <host_path>:<container_path>:<read_only>, where <read_only> is one of rw (for read-write access) or ro (for read-only access).
    
    foo:
      dockerng.running:
        - image: bar/baz:latest
        - binds: /srv/www:/var/www:ro,/etc/foo.conf:/usr/local/etc/foo.conf:rw
    Binds can be passed as a YAML list instead of a comma-separated list:
    
    foo:
      dockerng.running:
        - image: bar/baz:latest
        - binds:
          - /srv/www:/var/www:ro
          - /home/myuser/conf/foo.conf:/etc/foo.conf:rw
    Optionally, the read-only information can be left off the end and the bind mount will be assumed to be read-write. The example below is equivalent to the one above:
    
    foo:
      dockerng.running:
        - image: bar/baz:latest
        - binds:
          - /srv/www:/var/www:ro
          - /home/myuser/conf/foo.conf:/etc/foo.conf