Docker 遇到swapon failed Operation not permitted

在安装phalcon的时候遇到内存不足的问题,需要swap增加内存,可是在docker里面遇到

swapon failed: Operation not permitted

该问提百思不得其解,最后在docker官网找到了解释,最后说一下,搜索还是google靠谱

解决方法:

Hi, As each running docker container uses the host Kernel, they also use the memory and swap of the host. If this is a one of requirement its better to increase the host swap space. If you want to still add swap from the container you have two options. Run container in privileged mode In this case you will have to run the container with –privileged option.

Example One:

docker run -it –rm –privileged centos:6Running container with privileged mode gives container full privilege on the host. If you read the manpage of swapon you can see that for swapon to run the process should have CAP_SYS_ADMIN capability. In Docker you can add a particular capability selectively to the container using the –cap-add argument.

Example Two:

docker run -it –rm –cap-add SYS_ADMIN centos:6If you run the container in either of the above two modes you can achieve what you are trying.
Now the problem with this approach is , when you create swap inside the container and start using that, its actually the Host Kernel that is using it, as a result when you exit the container without a swapoff the host kernel will be still using the file, and you wont get a clean exit of the container. You will see a dead status for the container.

翻译:

由于每个运行的docker容器都使用主机内核,它们还使用主机的内存和交换。如果有需求,要求更好地使用主机交换空间的。如果你想从容器中添加交换,你有两个选择。

1. 以特权模式运行容器
在这种情况下,您将必须使用–privileged选项运行容器。
#示例

  • docker run -it –rm –privileged centos:6

2. 运行具有特权模式的容器可以为主机提供容器完整权限。

如果您阅读swapon的联机帮助页面,您可以看到,对于swapon来运行该进程应该具有CAP_SYS_ADMIN功能。在Docker中,您可以使用-cap-add参数有选择地向容器添加特定的功能。
#示例

  • docker run -it –rm –cap-add SYS_ADMIN centos:6

如果您以上述两种模式运行容器,您可以实现您正在尝试的功能。
现在,这种方法的问题是,当您在容器内创建交换并开始使用它时,实际上是使用它的主机内核,因此当您退出容器而不进行swapoff时,主机内核将仍然使用该文件,你不会得到一个干净的出口的容器。您将看到容器的死亡状态。

Docker 遇到swapon failed Operation not permitted相关推荐

  1. linux docker 报错 Failed to get D-Bus connection: Operation not permitted

    使用centos7镜像创建容器后,在里面使用systemctl启动服务报错.针对这个报错,我们接下来就分析下! # docker run -itd --name centos7 centos:7 # ...

  2. thingsboard集群docker swarm部署报getsockopt failed strangely: Operation not permitted

    thingsboard的集群部署通过docker-compose方式部署时没有出现任何问题,但是使用portainer(docker swarm)方式进行部署时haproxy服务报"gets ...

  3. docker strace ptrace 报错 Operation not permitted 解决方法

    docker中gdb在进行进程debug时,会报错: (gdb) attach 30721 Attaching to process 30721 ptrace: Operation not permi ...

  4. wsl centos7: Failed to get D-Bus connection: Operation not permitted

    wsl 运行的 centos 7,使用 service 命令提示 Failed to get D-Bus connection: Operation not permitted 错误,无法运行. 目前 ...

  5. 解决 CentOS7 容器 Failed to get D-Bus connection: Operation not permitted

    事由:通过 systemctl start crond 启动任务时报错,具体如下 Failed to get D-Bus connection: Operation not permitted 解决方 ...

  6. 登录mysql报错Failed to connect to backoff 或 Failed to get D-Bus connection: Operation not permitted解决方法

    报错: Failed to get D-Bus connection: Operation not permitted 或 mysql -u root -p 登录mysql时报错 2020-09-16 ...

  7. unpacking error : failed to extract...: failed to convert whiteout file... operation not permitted

    unpacking error : failed to extract-: failed to convert whiteout file- operation not permitted 问题背景: ...

  8. ctr: failed to extract layer ... failed to unmount ... operation not permitted: unknown

    ctr: failed to extract layer - failed to unmount - operation not permitted: unknown 问题背景: 在pod的conta ...

  9. 使用faketime修改docker内的时间,解决date: cannot set date: Operation not permitted问题

    使用faketime修改Docker容器时间,解决date:cannot set date operation not permitted问题 docker本质是个进程,有很多资源是使用宿主机的,比如 ...

最新文章

  1. Android应用源码安卓短信拦截木马项目源码
  2. Python:在Pandas数据框中查找缺失值
  3. LeetCode 1287. 有序数组中出现次数超过25%的元素
  4. ARM汇编编程基础之一 —— 寄存器
  5. PHP清除HTML代码、空格、回车换行符的函数
  6. mongodb 远程连接
  7. ESL系统的Docker化部署
  8. C# GIF图片的分解以及合成
  9. 2020-2022 抗疫营销案例合集(共17份)
  10. 爬虫不借助浏览器登录_借助Android音乐播放器和旅行组合踏上道路
  11. 最新苹果开发者账号添加设备UDID
  12. H5是什么?H5怎么做?带你全面了解H5游戏制作
  13. 【数据分析】京东2019校招数据分析工程师笔试题
  14. TypeScript深度剖析:Vue项目中应用TypeScript?
  15. 使用GDAL工具对OrbView-3数据进行正射校正
  16. 分布式三大利器之《消息队列》
  17. viper4android io错误,Go viper包处理JSON笔记
  18. 重要的统计量(期望、方差、协方差、相关系数、矩)的概念和性质
  19. 数据库系统h概论——1、基本的概念
  20. 计算机系统维护数据安全,计算机组装与维护电子教案09单元9悉心保证系统与数据安全.doc...

热门文章

  1. C# 实现软件自动更新升级程序
  2. Linux: 如何利用HandBrake将DVD光碟转成各式影片档
  3. 滚屏加载--无刷新动态加载数据技术的应用
  4. MYSQL模式匹配:REGEXP和like用法
  5. PHP 中使用工厂模式
  6. 非线性降维-核主成分分析KPCA
  7. Sublime与远程服务器代码同步工具SFTP
  8. 【python】 合并列表的方法
  9. 【今日CS 视觉论文速览】19 Dec 2018
  10. chrome谷歌浏览器安装教程 20200701