github.com/containers/podman/v5@v5.1.0-rc1/docs/source/markdown/options/volume.md (about) 1 ####> This option file is used in: 2 ####> podman create, pod clone, pod create, run 3 ####> If file is edited, make sure the changes 4 ####> are applicable to all of those. 5 #### **--volume**, **-v**=*[[SOURCE-VOLUME|HOST-DIR:]CONTAINER-DIR[:OPTIONS]]* 6 7 Create a bind mount. If `-v /HOST-DIR:/CONTAINER-DIR` is specified, Podman 8 bind mounts `/HOST-DIR` from the host into `/CONTAINER-DIR` in the Podman 9 container. Similarly, `-v SOURCE-VOLUME:/CONTAINER-DIR` mounts the named 10 volume from the host into the container. If no such named volume exists, 11 Podman creates one. If no source is given, the volume is created 12 as an anonymously named volume with a randomly generated name, and is 13 removed when the <<container|pod>> is removed via the `--rm` flag or 14 the `podman rm --volumes` command. 15 16 (Note when using the remote client, including Mac and Windows (excluding WSL2) machines, the volumes are mounted from the remote server, not necessarily the client machine.) 17 18 The _OPTIONS_ is a comma-separated list and can be one or more of: 19 20 * **rw**|**ro** 21 * **z**|**Z** 22 * [**O**] 23 * [**U**] 24 * [**no**]**copy** 25 * [**no**]**dev** 26 * [**no**]**exec** 27 * [**no**]**suid** 28 * [**r**]**bind** 29 * [**r**]**shared**|[**r**]**slave**|[**r**]**private**[**r**]**unbindable** <sup>[[1]](#Footnote1)</sup> 30 * **idmap**[=**options**] 31 32 The `CONTAINER-DIR` must be an absolute path such as `/src/docs`. The volume 33 is mounted into the container at this directory. 34 35 If a volume source is specified, it must be a path on the host or the name of a 36 named volume. Host paths are allowed to be absolute or relative; relative paths 37 are resolved relative to the directory Podman is run in. If the source does not 38 exist, Podman returns an error. Users must pre-create the source files or 39 directories. 40 41 Any source that does not begin with a `.` or `/` is treated as the name of 42 a named volume. If a volume with that name does not exist, it is created. 43 Volumes created with names are not anonymous, and they are not removed by the `--rm` 44 option and the `podman rm --volumes` command. 45 46 Specify multiple **-v** options to mount one or more volumes into a 47 <<container|pod>>. 48 49 `Write Protected Volume Mounts` 50 51 Add **:ro** or **:rw** option to mount a volume in read-only or 52 read-write mode, respectively. By default, the volumes are mounted read-write. 53 See examples. 54 55 `Chowning Volume Mounts` 56 57 By default, Podman does not change the owner and group of source volume 58 directories mounted into containers. If a <<container|pod>> is created in a new 59 user namespace, the UID and GID in the container may correspond to another UID 60 and GID on the host. 61 62 The `:U` suffix tells Podman to use the correct host UID and GID based on the 63 UID and GID within the <<container|pod>>, to change recursively the owner and 64 group of the source volume. Chowning walks the file system under the volume and 65 changes the UID/GID on each file. If the volume has thousands of inodes, this 66 process takes a long time, delaying the start of the <<container|pod>>. 67 68 **Warning** use with caution since this modifies the host filesystem. 69 70 `Labeling Volume Mounts` 71 72 Labeling systems like SELinux require that proper labels are placed on volume 73 content mounted into a <<container|pod>>. Without a label, the security system 74 might prevent the processes running inside the <<container|pod>> from using the 75 content. By default, Podman does not change the labels set by the OS. 76 77 To change a label in the <<container|pod>> context, add either of two suffixes 78 **:z** or **:Z** to the volume mount. These suffixes tell Podman to relabel file 79 objects on the shared volumes. The **z** option tells Podman that two or more 80 <<containers|pods>> share the volume content. As a result, Podman labels the 81 content with a shared content label. Shared volume labels allow all containers 82 to read/write content. The **Z** option tells Podman to label the content with 83 a private unshared label Only the current <<container|pod>> can use a private 84 volume. Relabeling walks the file system under the volume and changes the label 85 on each file, if the volume has thousands of inodes, this process takes a 86 long time, delaying the start of the <<container|pod>>. If the volume 87 was previously relabeled with the `z` option, Podman is optimized to not relabel 88 a second time. If files are moved into the volume, then the labels can be 89 manually change with the `chcon -Rt container_file_t PATH` command. 90 91 Note: Do not relabel system files and directories. Relabeling system content 92 might cause other confined services on the machine to fail. For these types 93 of containers we recommend disabling SELinux separation. The option 94 **--security-opt label=disable** disables SELinux separation for the <<container|pod>>. 95 For example if a user wanted to volume mount their entire home directory into a 96 <<container|pod>>, they need to disable SELinux separation. 97 98 $ podman <<fullsubcommand>> --security-opt label=disable -v $HOME:/home/user fedora touch /home/user/file 99 100 `Overlay Volume Mounts` 101 102 The `:O` flag tells Podman to mount the directory from the host as a 103 temporary storage using the `overlay file system`. The <<container|pod>> processes 104 can modify content within the mountpoint which is stored in the 105 container storage in a separate directory. In overlay terms, the source 106 directory is the lower, and the container storage directory is the 107 upper. Modifications to the mount point are destroyed when the <<container|pod>> 108 finishes executing, similar to a tmpfs mount point being unmounted. 109 110 For advanced users, the **overlay** option also supports custom non-volatile 111 **upperdir** and **workdir** for the overlay mount. Custom **upperdir** and 112 **workdir** can be fully managed by the users themselves, and Podman does not 113 remove it on lifecycle completion. 114 Example **:O,upperdir=/some/upper,workdir=/some/work** 115 116 Subsequent executions of the container sees the original source directory 117 content, any changes from previous <<container|pod>> executions no longer exist. 118 119 One use case of the overlay mount is sharing the package cache from the 120 host into the container to allow speeding up builds. 121 122 Note: The `O` flag conflicts with other options listed above. 123 124 Content mounted into the container is labeled with the private label. 125 On SELinux systems, labels in the source directory must be readable 126 by the <<|pod infra>> container label. Usually containers can read/execute `container_share_t` 127 and can read/write `container_file_t`. If unable to change the labels on a 128 source volume, SELinux container separation must be disabled for the <<|pod or infra>> container 129 to work. 130 131 Do not modify the source directory mounted into the <<container|pod>> with an overlay mount, 132 it can cause unexpected failures. Only modify the directory after the container finishes running. 133 134 `Mounts propagation` 135 136 By default, bind-mounted volumes are `private`. That means any mounts done 137 inside the <<container|pod>> are not visible on the host and vice versa. 138 One can change this behavior by specifying a volume mount propagation property. 139 When a volume is `shared`, mounts done under that volume inside the <<container|pod>> 140 are visible on host and vice versa. Making a volume **slave**<sup>[[1]](#Footnote1)</sup> 141 enables only one-way mount propagation: mounts done on the host under that volume 142 are visible inside the container but not the other way around. 143 144 To control mount propagation property of a volume one can use the [**r**]**shared**, 145 [**r**]**slave**, [**r**]**private** or the [**r**]**unbindable** propagation flag. 146 Propagation property can be specified only for bind mounted volumes and not for 147 internal volumes or named volumes. For mount propagation to work the source mount 148 point (the mount point where source dir is mounted on) has to have the right propagation 149 properties. For shared volumes, the source mount point has to be shared. And for 150 slave volumes, the source mount point has to be either shared or slave. 151 <sup>[[1]](#Footnote1)</sup> 152 153 To recursively mount a volume and all of its submounts into a 154 <<container|pod>>, use the **rbind** option. By default the bind option is 155 used, and submounts of the source directory is not mounted into the 156 <<container|pod>>. 157 158 Mounting the volume with a **copy** option tells podman to copy content from 159 the underlying destination directory onto newly created internal volumes. The 160 **copy** only happens on the initial creation of the volume. Content is not 161 copied up when the volume is subsequently used on different containers. The 162 **copy** option is ignored on bind mounts and has no effect. 163 164 Mounting volumes with the **nosuid** options means that SUID executables on the 165 volume can not be used by applications to change their privilege. By default 166 volumes are mounted with **nosuid**. 167 168 Mounting the volume with the **noexec** option means that no executables on the 169 volume can be executed within the <<container|pod>>. 170 171 Mounting the volume with the **nodev** option means that no devices on the volume 172 can be used by processes within the <<container|pod>>. By default volumes 173 are mounted with **nodev**. 174 175 If the _HOST-DIR_ is a mount point, then **dev**, **suid**, and **exec** options are 176 ignored by the kernel. 177 178 Use **df HOST-DIR** to figure out the source mount, then use 179 **findmnt -o TARGET,PROPAGATION _source-mount-dir_** to figure out propagation 180 properties of source mount. If **findmnt**(1) utility is not available, then one 181 can look at the mount entry for the source mount point in _/proc/self/mountinfo_. Look 182 at the "optional fields" and see if any propagation properties are specified. 183 In there, **shared:N** means the mount is shared, **master:N** means mount 184 is slave, and if nothing is there, the mount is private. <sup>[[1]](#Footnote1)</sup> 185 186 To change propagation properties of a mount point, use **mount**(8) command. For 187 example, if one wants to bind mount source directory _/foo_, one can do 188 **mount --bind /foo /foo** and **mount --make-private --make-shared /foo**. This 189 converts /foo into a shared mount point. Alternatively, one can directly 190 change propagation properties of source mount. Say _/_ is source mount for 191 _/foo_, then use **mount --make-shared /** to convert _/_ into a shared mount. 192 193 Note: if the user only has access rights via a group, accessing the volume 194 from inside a rootless <<container|pod>> fails. 195 196 `Idmapped mount` 197 198 If `idmap` is specified, create an idmapped mount to the target user 199 namespace in the container. The idmap option supports a custom mapping 200 that can be different than the user namespace used by the 201 container. The mapping can be specified after the idmap option like: 202 `idmap=uids=0-1-10#10-11-10;gids=0-100-10`. 203 For each triplet, the first value is the start of the backing file 204 system IDs that are mapped to the second value on the host. The 205 length of this mapping is given in the third value. 206 Multiple ranges are separated with #.