@@ -24,7 +24,7 @@ sub run {
2424
2525 # From https://docs.docker.com/storage/bind-mounts/
2626 # The --mount flag does not support z or Z options for modifying selinux labels.
27- my $Z = $runtime eq " podman" ? " ,Z " : " " ;
27+ my $z = $runtime eq " podman" ? " ,z " : " " ;
2828
2929 my $test_file = " test_file" ;
3030 my $test_image = " test_image" ;
@@ -36,6 +36,12 @@ sub run {
3636 # Create Dockerfile with VOLUME defined
3737 assert_script_run(" echo -e 'FROM registry.opensuse.org/opensuse/busybox:latest\\ nVOLUME /$test_dir ' > $test_dir /Dockerfile" );
3838
39+ if ($runtime eq " docker" ) {
40+ my $selinux_enabled = script_run(" test -d /sys/fs/selinux" ) == 0;
41+ # Apply fix suggested in docker-run(1)
42+ assert_script_run(" chcon -Rt svirt_sandbox_file_t test_dir" ) if $selinux_enabled ;
43+ }
44+
3945 # Build image
4046 assert_script_run(" $runtime build -t $test_image -f $test_dir /Dockerfile $test_dir /" );
4147
@@ -48,29 +54,29 @@ sub run {
4854 # Case 2: Check that the volume from container is visible in another container, but the
4955 # first container is mounting it in the directory specified as VOLUME in the Dockerfile
5056 assert_script_run(" touch $test_dir /$test_file " );
51- assert_script_run(" $runtime run -d --name $test_container -v \$ PWD/$test_dir :/$test_dir :Z $test_image " );
57+ assert_script_run(" $runtime run -d --name $test_container -v \$ PWD/$test_dir :/$test_dir :z $test_image " );
5258 assert_script_run(" $runtime run --rm --volumes-from $test_container $test_image ls /$test_dir /$test_file " );
5359
5460 assert_script_run(" $runtime rm -vf $test_container " );
5561
5662 # Test --volume option with directory (read-only)
57- assert_script_run(" ! $runtime run --rm --volume \$ PWD/$test_dir :/$test_dir :ro,Z $test_image rm /$test_dir /$test_file " );
63+ assert_script_run(" ! $runtime run --rm --volume \$ PWD/$test_dir :/$test_dir :ro,z $test_image rm /$test_dir /$test_file " );
5864 assert_script_run(" test -f $test_dir /$test_file " );
5965
6066 # Equivalent --mount option to above
61- assert_script_run(" ! $runtime run --rm --mount type=bind,source=\$ PWD/$test_dir ,destination=/$test_dir ,readonly$Z $test_image rm /$test_dir /$test_file " );
67+ assert_script_run(" ! $runtime run --rm --mount type=bind,source=\$ PWD/$test_dir ,destination=/$test_dir ,readonly$z $test_image rm /$test_dir /$test_file " );
6268 assert_script_run(" test -f $test_dir /$test_file " );
6369
6470 assert_script_run(" rm $test_dir /$test_file " );
6571
6672 # Test --volume option with directory (read-write)
67- assert_script_run(" $runtime run --rm --volume \$ PWD/$test_dir :/$test_dir :Z $test_image touch /$test_dir /$test_file " );
73+ assert_script_run(" $runtime run --rm --volume \$ PWD/$test_dir :/$test_dir :z $test_image touch /$test_dir /$test_file " );
6874 assert_script_run(" test -f $test_dir /$test_file " );
6975
7076 assert_script_run(" rm $test_dir /$test_file " );
7177
7278 # Equivalent --mount option to above
73- assert_script_run(" $runtime run --rm --mount type=bind,source=\$ PWD/$test_dir ,destination=/${test_dir}$Z $test_image touch /$test_dir /$test_file " );
79+ assert_script_run(" $runtime run --rm --mount type=bind,source=\$ PWD/$test_dir ,destination=/${test_dir}$z $test_image touch /$test_dir /$test_file " );
7480 assert_script_run(" test -f $test_dir /$test_file " );
7581
7682 # Test volume subcommands
@@ -94,14 +100,14 @@ sub run {
94100 assert_script_run(" test -f $test_dir /$test_file " );
95101
96102 # Equivalent --mount option to above
97- assert_script_run(" $runtime run --rm --mount type=volume,source=$test_volume ,destination=/$test_dir$Z $test_image touch /$test_dir /$test_file " );
103+ assert_script_run(" $runtime run --rm --mount type=volume,source=$test_volume ,destination=/$test_dir$z $test_image touch /$test_dir /$test_file " );
98104
99105 # Test --volume option with volume (read-only)
100106 assert_script_run(" ! $runtime run --rm --volume $test_volume :/$test_dir :ro $test_image rm /$test_dir /$test_file " );
101107 assert_script_run(" test -f $test_dir /$test_file " );
102108
103109 # Equivalent --mount option to above
104- assert_script_run(" ! $runtime run --rm --mount type=volume,source=$test_volume ,destination=/$test_dir ,readonly$Z $test_image rm /$test_dir /$test_file " );
110+ assert_script_run(" ! $runtime run --rm --mount type=volume,source=$test_volume ,destination=/$test_dir ,readonly$z $test_image rm /$test_dir /$test_file " );
105111
106112 assert_script_run(" $runtime volume rm $test_volume " );
107113 assert_script_run(" ! $runtime volume inspect $test_volume " );
0 commit comments