diff --git a/README.md b/README.md index 541875e034..0a06380328 100644 --- a/README.md +++ b/README.md @@ -1019,11 +1019,10 @@ Most `docker_container` properties are the `snake_case` version of the - `command` - The command to run when starting the container. - `autoremove` - Boolean - Automatically delete a container when it's command exits. Defaults to `false`. -- `binds` - An array of volume bindings for this container. Each volume binding - is a string in one of these forms: - `container_path` to create a new volume for the container. - `host_path:container_path` to bind-mount a host path into the container. - `host_path:container_path:ro` to make the bind-mount read-only inside the container. +- `binds` - An array of `:` separated paths to bind mount from the + host into the container in the form + `['/host-bits:/container-bits', '/more-host-bits:/more-container-bits']`. + Defaults to `nil`. - `cap_add` - An array Linux Capabilities (`man 7 capabilities`) to add to grant the container beyond what it normally gets. - `cap_drop` - An array Linux Capabilities (`man 7 capabilities`) to @@ -1087,6 +1086,9 @@ Most `docker_container` properties are the `snake_case` version of the Defaults to `SIGKILL`. - `tty` - Boolean value to allocate a pseudo-TTY. Defaults to `false`. - `user` - A string value specifying the user inside the container. +- `volumes` - An Array of paths inside the container to expose. Does + the same thing as the `VOLUME` directive in a Dockerfile, but works + on container creation. - `volumes_from` - A list of volumes to inherit from another container. Specified in the form `[:]` - `working_dir` - A string specifying the working directory for diff --git a/libraries/docker_container.rb b/libraries/docker_container.rb index 1b39d5e779..790e5420eb 100644 --- a/libraries/docker_container.rb +++ b/libraries/docker_container.rb @@ -36,7 +36,7 @@ class DockerContainer < DockerBase property :attach_stdin, Boolean, desired_state: false property :attach_stdout, Boolean, desired_state: false property :autoremove, Boolean, desired_state: false - property :binds, ArrayType, coerce: proc { |v| coerce_binds(v) } + property :binds, ArrayType property :cap_add, NonEmptyArray property :cap_drop, NonEmptyArray property :cgroup_parent, String, default: '' diff --git a/libraries/helpers_container.rb b/libraries/helpers_container.rb index 7e6d276b14..4cffc1db1a 100644 --- a/libraries/helpers_container.rb +++ b/libraries/helpers_container.rb @@ -39,23 +39,6 @@ def coerce_ulimits(v) end end - def coerce_binds(v) - return v if v.nil? - Array(v).delete_if do |x| - parts = x.split(':') - if parts.length == 1 - container_path = parts[0] - if property_is_set?(:volumes) - volumes.merge!(coerce_volumes(container_path)) - else - volumes container_path - end - next true - end - false - end - end - def coerce_volumes(v) case v when nil, DockerBase::PartialHash @@ -120,7 +103,7 @@ def parse_port(v) if port_range.include?('-') port_range = container_port.split('-') port_range.map!(&:to_i) - fail Chef::Exceptions::ValidationFailed, "Invalid port range! #{container_port}" if port_range[0] > port_range[1] + Chef::Log.fatal("FATAL: Invalid port range! #{container_port}") if port_range[0] > port_range[1] port_range = (port_range[0]..port_range[1]).to_a end # qualify the port-binding protocol even when it is implicitly tcp #427. diff --git a/spec/docker_test/container_spec.rb b/spec/docker_test/container_spec.rb index 1fdbd7ff68..1b44d8ea30 100644 --- a/spec/docker_test/container_spec.rb +++ b/spec/docker_test/container_spec.rb @@ -268,8 +268,7 @@ expect(chef_run).to run_if_missing_docker_container('bind_mounter').with( repo: 'busybox', command: 'ls -la /bits /more-bits', - binds: ['/hostbits:/bits', '/more-hostbits:/more-bits'], - volumes: { '/snow' => {}, '/winter' => {} } + binds: ['/hostbits:/bits', '/more-hostbits:/more-bits'] ) end end diff --git a/test/cookbooks/docker_test/recipes/container.rb b/test/cookbooks/docker_test/recipes/container.rb index a164b7fe94..90e7bdc8d6 100644 --- a/test/cookbooks/docker_test/recipes/container.rb +++ b/test/cookbooks/docker_test/recipes/container.rb @@ -278,7 +278,7 @@ docker_container 'bind_mounter' do repo 'busybox' command 'ls -la /bits /more-bits' - binds ['/hostbits:/bits', '/more-hostbits:/more-bits', '/snow', '/winter'] + binds ['/hostbits:/bits', '/more-hostbits:/more-bits'] action :run_if_missing end @@ -316,7 +316,7 @@ # create a volume container docker_container 'chef_container' do command 'true' - binds '/opt/chef' + volumes '/opt/chef' action :create end @@ -395,7 +395,6 @@ repo 'debian' volumes_from 'chef_container' autoremove true - detach false not_if { ::File.exist? '/marker_container_sean_was_here' } action :run end @@ -804,8 +803,9 @@ mac_address '00:00:DE:AD:BE:EF' network_disabled false tty true + volumes ['/root'] working_dir '/' - binds ['/root', '/hostbits:/bits', '/more-hostbits:/more-bits'] + binds ['/hostbits:/bits', '/more-hostbits:/more-bits'] cap_add %w(NET_ADMIN SYS_RESOURCE) cap_drop 'MKNOD' cpu_shares 512 @@ -876,7 +876,7 @@ user 'operator' command 'sh -c "trap exit 0 SIGTERM; while :; do sleep 1; done"' env ['FOO=biz'] - binds '/var/log' + volumes '/var/log' workdir '/tmp' port ['9988:9988', '8877:8877'] action :run diff --git a/test/integration/resources-162/serverspec/assert_functioning_spec.rb b/test/integration/resources-162/serverspec/assert_functioning_spec.rb index 6c396166b0..b1f2973ab6 100644 --- a/test/integration/resources-162/serverspec/assert_functioning_spec.rb +++ b/test/integration/resources-162/serverspec/assert_functioning_spec.rb @@ -331,12 +331,6 @@ its(:stdout) { should match(%r{\[\/hostbits\:\/bits \/more-hostbits\:\/more-bits\]}) } end -describe command("docker inspect -f \"{{ .Config.Volumes }}\" bind_mounter") do - its(:exit_status) { should eq 0 } - its(:stdout) { should match(%r{\/snow:\{\}}) } - its(:stdout) { should match(%r{\/winter:\{\}}) } -end - # docker_container[chef_container] describe command("docker ps -af 'name=chef_container$'") do diff --git a/test/integration/resources-171/serverspec/assert_functioning_spec.rb b/test/integration/resources-171/serverspec/assert_functioning_spec.rb index 6c396166b0..b1f2973ab6 100644 --- a/test/integration/resources-171/serverspec/assert_functioning_spec.rb +++ b/test/integration/resources-171/serverspec/assert_functioning_spec.rb @@ -331,12 +331,6 @@ its(:stdout) { should match(%r{\[\/hostbits\:\/bits \/more-hostbits\:\/more-bits\]}) } end -describe command("docker inspect -f \"{{ .Config.Volumes }}\" bind_mounter") do - its(:exit_status) { should eq 0 } - its(:stdout) { should match(%r{\/snow:\{\}}) } - its(:stdout) { should match(%r{\/winter:\{\}}) } -end - # docker_container[chef_container] describe command("docker ps -af 'name=chef_container$'") do diff --git a/test/integration/resources-183/serverspec/assert_functioning_spec.rb b/test/integration/resources-183/serverspec/assert_functioning_spec.rb index 6c396166b0..b1f2973ab6 100644 --- a/test/integration/resources-183/serverspec/assert_functioning_spec.rb +++ b/test/integration/resources-183/serverspec/assert_functioning_spec.rb @@ -331,12 +331,6 @@ its(:stdout) { should match(%r{\[\/hostbits\:\/bits \/more-hostbits\:\/more-bits\]}) } end -describe command("docker inspect -f \"{{ .Config.Volumes }}\" bind_mounter") do - its(:exit_status) { should eq 0 } - its(:stdout) { should match(%r{\/snow:\{\}}) } - its(:stdout) { should match(%r{\/winter:\{\}}) } -end - # docker_container[chef_container] describe command("docker ps -af 'name=chef_container$'") do diff --git a/test/integration/resources-191/serverspec/assert_functioning_spec.rb b/test/integration/resources-191/serverspec/assert_functioning_spec.rb index 6c396166b0..b1f2973ab6 100644 --- a/test/integration/resources-191/serverspec/assert_functioning_spec.rb +++ b/test/integration/resources-191/serverspec/assert_functioning_spec.rb @@ -331,12 +331,6 @@ its(:stdout) { should match(%r{\[\/hostbits\:\/bits \/more-hostbits\:\/more-bits\]}) } end -describe command("docker inspect -f \"{{ .Config.Volumes }}\" bind_mounter") do - its(:exit_status) { should eq 0 } - its(:stdout) { should match(%r{\/snow:\{\}}) } - its(:stdout) { should match(%r{\/winter:\{\}}) } -end - # docker_container[chef_container] describe command("docker ps -af 'name=chef_container$'") do