docker - Ubuntu 上 Docker 容器中的“mount --bind”命令失败
问题描述
在我在 Ubuntu 20.04 上的应用程序中,由于 chroot 的挂载目录,我需要执行以下命令:
% execute outside the Docker container
# cd /tmp
# mkdir a b
# mount --bind a b
如果我不使用 Docker 容器,这mount --bind
将成功。
但是,相同的命令在 Docker 容器中会失败:
% execute in the docker container
# cd /app-data/
# mkdir a b
# mount --bind a b
mount: /app-data/b: bind /app-data/a failed.
我描述cap_add: SYS_ADMIN
了docker-compose.yaml
启动容器。
我怎么解决这个问题?
作为参考,这里是执行环境的文件系统信息:
% execute in the docker container
# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
overlay overlay 99014644 5453880 88511424 6% /
tmpfs tmpfs 65536 0 65536 0% /dev
tmpfs tmpfs 1017552 0 1017552 0% /sys/fs/cgroup
/dev/vda3 ext4 99014644 5453880 88511424 6% /app-data
shm tmpfs 65536 0 65536 0% /dev/shm
tmpfs tmpfs 1017552 0 1017552 0% /proc/acpi
tmpfs tmpfs 1017552 0 1017552 0% /proc/scsi
tmpfs tmpfs 1017552 0 1017552 0% /sys/firmware
% execute outside the Docker container
# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
udev devtmpfs 973876 0 973876 0% /dev
tmpfs tmpfs 203512 828 202684 1% /run
/dev/vda3 ext4 99014644 5453880 88511424 6% /
tmpfs tmpfs 1017552 0 1017552 0% /dev/shm
tmpfs tmpfs 5120 0 5120 0% /run/lock
tmpfs tmpfs 1017552 0 1017552 0% /sys/fs/cgroup
tmpfs tmpfs 203508 0 203508 0% /run/user/1000
overlay overlay 99014644 5453880 88511424 6% /var/lib/docker/overlay2/a393b5ab8ef81eb83d27565bc4695bbc899543aa075cbf7c1ccf6246ce846008/merged
shm tmpfs 65536 16 65520 1% /var/lib/docker/containers/a4f2d1eff4b1a3ef1b8622fad4b529901fb415d77f17a31e8d9a0ed332d3819e/mounts/shm
overlay overlay 99014644 5453880 88511424 6% /var/lib/docker/overlay2/a7453522f3e4a9f27c3cb20b0f3f4ebe75358ed9f5f909810ca18d836a601282/merged
shm tmpfs 65536 0 65536 0% /var/lib/docker/containers/66a76b08846fbe38f633976bc8950ee414f867419310f8c612ce3aace8abfe0f/mounts/shm
解决方案
推荐阅读
- laravel - 如何修复 laravel 关系查询 where 子句?
- sql - 从另一个表 postgres 更新表时如何执行 upsert?
- pact - chainweb 编译时的 nix-build 失败
- python - Python:无法从 hashlib 导入 scrypt
- ansible - 将循环值传递给 Ansible 调试消息的问题
- kotlin - 实例化 AndroidViewModel 子类时出现“不是子类型”错误
- c# - 使用 delta 的单体游戏精灵运动不平滑
- sql-server - BIT 非选择性列上的 SQL Server 索引
- batch-file - 批处理脚本在 if 语句处崩溃
- php - 如何在 PHP 端获取我的数组的值,并将它们插入到我的数据库中?