--mount='type=volume,dst=/external-drive,volume-driver=local,volume-opt=device=/dev/loop5,volume-opt=type=ext4'
```
You can't run the `mount` command inside the container directly,
because the container is unable to access the `/dev/loop5` device.
That's why the `docker run` command uses the `--mount` option.
#### Example: Mounting a block device in a container
The following steps create an `ext4` filesystem and mounts it into a container.
The filesystem support of your system depends on the version of the Linux kernel you are using.
1. Create a file and allocate some space to it:
```console
$ fallocate -l 1G disk.raw
```
2. Build a filesystem onto the `disk.raw` file:
```console
$ mkfs.ext4 disk.raw
```
3. Create a loop device:
```console
$ losetup -f --show disk.raw
/dev/loop5
```
> [!NOTE]
>
> `losetup` creates an ephemeral loop device that's removed after
> system reboot, or manually removed with `losetup -d`.
4. Run a container that mounts the loop device as a volume:
```console
$ docker run -it --rm \
--mount='type=volume,dst=/external-drive,volume-driver=local,volume-opt=device=/dev/loop5,volume-opt=type=ext4' \
ubuntu bash
```
When the container starts, the path `/external-drive` mounts the
`disk.raw` file from the host filesystem as a block device.
5. When you're done, and the device is unmounted from the container,
detach the loop device to remove the device from the host system:
```console
$ losetup -d /dev/loop5
```
## Back up, restore, or migrate data volumes
Volumes are useful for backups, restores, and migrations.
Use the `--volumes-from` flag to create a new container that mounts that volume.
### Back up a volume
For example, create a new container named `dbstore`:
```console
$ docker run -v /dbdata --name dbstore ubuntu /bin/bash
```
In the next command:
- Launch a new container and mount the volume from the `dbstore` container
- Mount a local host directory as `/backup`
- Pass a command that tars the contents of the `dbdata` volume to a `backup.tar` file inside the `/backup` directory.