Docker之常见FAQ记录清单

一、前言

在这里插入图片描述

本文记录Docker使用过程中遇见的问题,供后续回顾参考。

在这里插入图片描述

关联资源:网络Docker博客、官方FAQ、文档、Docker 从入门到实践、中文社区、riptutorial

二、问题及处理记录

2.1、docker容器内没有vi,nano等编辑器

1)如果宿主机本地有,可映射到docker容器内,但vim会有共享库限制;

docker run -v /usr/bin/vi:/usr/bin/vi --name mysql_soft image_name

2)docker容器内执行apt update报错:

Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8786 kB]
Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13.8 kB]
Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [155 kB]
Fetched 9209 kB in 2s (5838 kB/s)
Reading package lists…
E: Problem executing scripts APT::Update::Post-Invoke ‘rm -f /var/cache/apt/archives/.deb /var/cache/apt/archives/partial/.deb /var/cache/apt/*.bin || true’
E: Sub-process returned an error code

分析处理过程:

//docker网络检查
docker run redis apt update  #宿主机执行更新检查,报错同上,ping deb.debian.org通,网络正常
//相关经验表明:Docker version 20.10.9以及以下版本使用apt有问题,要么升级,要么执行如下临时修改,
sed -i -e 's/^APT/# APT/' -e 's/^DPkg/# DPkg/' /etc/apt/apt.conf.d/docker-clean
#现场docker版本
docker --version
Docker version 20.10.7, build f0df350
#查看可从软件源安装的软件包的版本列表
apt-cache madison <package_name>
#容器OS版本
 cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
#修改docker-clean文件后再次执行:
apt update  #输出如下
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian bookworm-updates InRelease
Hit:3 http://deb.debian.org/debian-security bookworm-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.

#安装再次报错:apt-get install vim -y

 dpkg-deb --control subprocess returned error exit status 2
dpkg-deb (subprocess): decompressing archive '/tmp/apt-dpkg-install-UoSzsi/3-vim-runtime_2%3a9.0.1378-2_all.deb' (size=7025180) member 'control.tar': lzma error: Cannot allocate memory
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
dpkg-deb: error: tar subprocess returned error exit status 2
dpkg: error processing archive /tmp/apt-dpkg-install-UoSzsi/3-vim-runtime_2%3a9.0.1378-2_all.deb (--unpack):
 dpkg-deb --control subprocess returned error exit status 2
dpkg-deb (subprocess): decompressing archive '/tmp/apt-dpkg-install-UoSzsi/4-vim_2%3a9.0.1378-2_amd64.deb' (size=1567304) member 'control.tar': lzma error: Cannot allocate memory
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
dpkg-deb: error: tar subprocess returned error exit status 2
dpkg: error processing archive /tmp/apt-dpkg-install-UoSzsi/4-vim_2%3a9.0.1378-2_amd64.deb (--unpack):
 dpkg-deb --control subprocess returned error exit status 2
dpkg-deb (subprocess): decompressing archive '/tmp/apt-dpkg-install-UoSzsi/5-xxd_2%3a9.0.1378-2_amd64.deb' (size=83680) member 'control.tar': lzma error: Cannot allocate memory
#容器因与宿主机共用内核,所以需修改内核参数
vim /etc/sysctl.conf  #新增
fs.file-max = 1500000
fs.nr_open = 1500000
net.core.somaxconn = 2048
vm.overcommit_memory = 1

或:echo 1 > /proc/sys/vm/overcommit_memory
#为容器分配内存和交换空间,--memory-swap 参数用于设置容器可使用的总交换空间大小(包括内存和交换分区)。这个值必须大于或等于指定的 --memory 参数值
docker inspect --format='{{.HostConfig.MemoryReservation}}, {{.HostConfig.MemorySwap}}' 
docker update redis -m 512m --memory-swap -1  #其中,容器能够使用无限的交换空间,可以设置 --memory-swap 为 -1

#要想让所有容器这2个值一样,直接修改宿主机的
vim /etc/docker/daemon.json
 {
  "default-memory-swap": "2g",
  "default-memory": "1g"
}

## 结果还是不行,没有权限修改,/etc/security/limit.conf为只读,出于安全和一致性的考虑,Docker 容器通常以只读的方式挂载许多系统文件和目录
docker run --user $(id -u):$(id -g) your-image
docker run --itd --privileged=true --name redis redis /bin/bash   #其中,privileged=true:获得真正的root权限,使其能够访问宿主机的所有设备,并且可以执行一些通常需要特权的操作,但不一定能够直接修改 /etc/security/limit.conf 文件
docker run -it --ulimit nofile=1024:4096 redis  #参数修改,nofile 表示文件描述符的数量,1024:4096 分别表示软限制和硬限制。

#修改为镜像,提交
docker commit -m “备注” -a “作者” 容器id 镜像repository

## 反构建通过镜像生成对应的dockfile文件
git clone https://github.com/CenturyLinkLabs/dockerfile-from-image.git
cd dockerfile-from-image
./bin/dockerfile-from-image <image_name> > Dockerfile
#配合
docker history <image_name>  #修改Dockerfile

2.2、Docker容器工具补充

#补充ps命令
apt update
apt install procps  #输出
Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8786 kB]
Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13.8 kB]
Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [155 kB]
Fetched 9209 kB in 4s (2066 kB/s)                    
Reading package lists... Done
root@3d19f505db4d:/var/log# apt-get install procps
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libgpm2 libncursesw6 libproc2-0 psmisc
Suggested packages:
  gpm
The following NEW packages will be installed:
  libgpm2 libncursesw6 libproc2-0 procps psmisc
0 upgraded, 5 newly installed, 0 to remove and 2 not upgraded.
Need to get 1178 kB of archives.
After this operation, 3778 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian bookworm/main amd64 libncursesw6 amd64 6.4-4 [134 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 libproc2-0 amd64 2:4.0.2-3 [62.8 kB]
Get:3 http://deb.debian.org/debian bookworm/main amd64 procps amd64 2:4.0.2-3 [709 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 libgpm2 amd64 1.20.7-10+b1 [14.2 kB]
Get:5 http://deb.debian.org/debian bookworm/main amd64 psmisc amd64 23.6-1 [259 kB]
Fetched 1178 kB in 1s (2023 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libncursesw6:amd64.
(Reading database ... 6101 files and directories currently installed.)
Preparing to unpack .../libncursesw6_6.4-4_amd64.deb ...
Unpacking libncursesw6:amd64 (6.4-4) ...
Selecting previously unselected package libproc2-0:amd64.
Preparing to unpack .../libproc2-0_2%3a4.0.2-3_amd64.deb ...
Unpacking libproc2-0:amd64 (2:4.0.2-3) ...
Selecting previously unselected package procps.
Preparing to unpack .../procps_2%3a4.0.2-3_amd64.deb ...
Unpacking procps (2:4.0.2-3) ...
Selecting previously unselected package libgpm2:amd64.
Preparing to unpack .../libgpm2_1.20.7-10+b1_amd64.deb ...
Unpacking libgpm2:amd64 (1.20.7-10+b1) ...
Selecting previously unselected package psmisc.
Preparing to unpack .../psmisc_23.6-1_amd64.deb ...
Unpacking psmisc (23.6-1) ...
Setting up libgpm2:amd64 (1.20.7-10+b1) ...
Setting up psmisc (23.6-1) ...
Setting up libproc2-0:amd64 (2:4.0.2-3) ...
Setting up libncursesw6:amd64 (6.4-4) ...
Setting up procps (2:4.0.2-3) ...

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/578702.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

vs2019 - warning LNK4098 : 默认库“msvcrt.lib”与其他库的使用冲突

文章目录 vs2019 - warning LNK4098 : 默认库“msvcrt.lib”与其他库的使用冲突概述笔记实验 - 编译静态库实验 - 编译主工程&#xff0c;包含静态库实验主工程和静态库编译设置不同时的编译报错和警告备注备注 - 判断/Mdd, /MdEND vs2019 - warning LNK4098 : 默认库“msvcrt.…

[SWPUCTF-2022-新生赛]ez_sql

title:[SWPUCTF 2022 新生赛]ez_sql 审题 根据提示&#xff0c;POST传参 得到假的flag 判断类型 字符型注入 判断列数 发现空格和’or’被过滤 重新构造 nss-1/**/oorrder/**/by/**/4#发现为3个字段 采用联合注入union 爆库 发现union被过滤&#xff0c;双写union绕过 发…

以生命健康为中心的物联网旅居养老运营平台

随着科技的飞速发展和人口老龄化的日益加剧&#xff0c;养老问题逐渐成为社会关注的焦点。传统的养老模式已经难以满足现代老年人的多元化需求&#xff0c;因此&#xff0c;构建一个以生命健康为中心的物联网旅居养老运营平台显得尤为重要。 以生命健康为中心的物联网旅居养老运…

两大成果发布!“大规模量子云算力集群”和高性能芯片展示中国科技潜力

在当前的科技领域&#xff0c;量子计算的进步正日益引起全球的关注。中国在这一领域的进展尤为显著&#xff0c;今天&#xff0c;北京量子信息科学研究院&#xff08;以下简称北京量子院&#xff09;和中国科学院量子信息与量子科技创新研究院&#xff08;以下简称量子创新院&a…

【c++】深入剖析与动手实践:C++中Stack与Queue的艺术

&#x1f525;个人主页&#xff1a;Quitecoder &#x1f525;专栏&#xff1a;c笔记仓 朋友们大家好&#xff0c;本篇文章我们来到STL新的内容&#xff0c;stack和queue 目录 1. stack的介绍与使用函数介绍例题一&#xff1a;最小栈例题二&#xff1a;栈的压入、弹出队列栈的模…

Docker 的数据管理 与 Docker 镜像的创建

目录 一、Docker 的数据管理 1.1.数据卷 1.2.数据卷容器 1.3.容器互联&#xff08;使用centos镜像&#xff09; 二、Docker 镜像的创建 2.1.基于现有镜像创建 2.2.基于本地模板创建 2.3.基于Dockerfile创建 2.3.1联合文件系统&#xff08;UnionFs&#xff09; 2.3.2…

GDPU 竞赛技能实践 天码行空9

1. 埃式筛法 求区间[2, n]内所有的素数对 &#x1f496; Main.java import java.util.Scanner;public class Main {static int N (int) 1e8, cnt 0;static int[] p new int[N];static boolean[] st new boolean[N];public static void main(String[] args){Scanner sc …

使用grasshopper修改梁的起始点方向

一般北方向朝上的情况&#xff0c;梁的方向从南向北&#xff0c;从西向东。 现在使用grasshopper来判断起始点坐标&#xff0c;分辨是否错误。 交换起始点这个&#xff0c;我实在不会用电池操作&#xff0c;只好敲python代码实现了。代码如下&#xff1a; 如果会敲代码的同学…

66.网络游戏逆向分析与漏洞攻防-利用数据包构建角色信息-重新规划游戏分析信息的输出

免责声明&#xff1a;内容仅供学习参考&#xff0c;请合法利用知识&#xff0c;禁止进行违法犯罪活动&#xff01; 如果看不懂、不知道现在做的什么&#xff0c;那就跟着做完看效果&#xff0c;代码看不懂是正常的&#xff0c;只要会抄就行&#xff0c;抄着抄着就能懂了 内容…

Apache Seata的可观测实践

title: Seata的可观测实践 keywords: [Seata、分布式事务、数据一致性、微服务、可观测] description: 本文介绍Seata在可观测领域的探索和实践 author: 刘戎-Seata 本文来自 Apache Seata官方文档&#xff0c;欢迎访问官网&#xff0c;查看更多深度文章。 Seata简介 Seata的…

STM32单片机通过ST-Link 烧录和调试

系列文章目录 STM32单片机系列专栏 C语言术语和结构总结专栏 1. ST-LINK V2 ST LINK v2下载器用于STM32单片机&#xff0c;可以下载程序、调试程序、读取芯片数据&#xff0c;解除芯片读写保护等等&#xff0c;辅助软件用的是STM32 ST-LINK Utility。 STM32 ST-LINK Utility…

电脑上的任务管理器不见了?如何把它打开?

前言 今天小白在睡觉的时候突然梦见回到了学校的电脑教室…… 相信大家都会有体验&#xff1a;每次上电脑课的时候&#xff0c;老师都会通过某些软件监控和控制学生的电脑。 想退出被控端的软件&#xff1f;没机会&#xff01;毕竟任务管理器也被禁用了&#xff0c;想整活都…

算法学习之单调栈

发射站 题目描述 某地有 N N N 个能量发射站排成一行&#xff0c;每个发射站 i i i 都有不相同的高度 H i H_i Hi​&#xff0c;并能向两边&#xff08;两端的发射站只能向一边&#xff09;同时发射能量值为 V i V_i Vi​ 的能量&#xff0c;发出的能量只被两边最近的且比…

Opencv_14_多边形填充与绘制

绘制多边形&#xff1a; 1&#xff09;coInvert.polyline_drawing(src); 2&#xff09;void ColorInvert::polyline_drawing(Mat& image) { Mat canvas Mat::zeros(Size(512, 512), CV_8UC3); Point p1(100, 100); Point p2(150, 100); Point p3(200…

TR6 - Transformer实战 单词预测

&#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 目录 理论知识关于数据集 Wikitext-2 模型结构代码实现0. 环境1. 加载数据集2. 模型搭建3. 创建模型4. 单轮训练和评估的流程5. 训练 模型效果总结与心得体会 …

Openharmony - 设备异常关机Power Down问题分析

By: fulinux E-mail: fulinux@sina.com Blog: https://blog.csdn.net/fulinus 喜欢的盆友欢迎点赞和订阅! 你的喜欢就是我写作的动力! 目录 1.问题描述1.1出现power down的原因1.1.1硬件故障或信号1.1.2软件错误或系统崩溃2.抓日志信息2.1.抓日志方法2.2.问题初步分析3.问题排…

React复习笔记

基础语法 创建项目 借助脚手架&#xff0c;新建一个React项目(可以使用vite或者cra&#xff0c;这里使用cra) npx create-react-app 项目名 create-react-app是React脚手架的名称 启动项目 npm start 或者 yarn start src是源文件index.js相当于Vue的main.js文件。整个…

OC类与对象

OC类与对象 本篇是对上一篇的内容的继续学习。从单例模式开始继续学习 文章目录 单例模式定义应用场景特点单例模式的创建 隐藏与封装理解什么是封装目的访问控制符合成存取方法特性的指示符点语法访问属性 对象初始化便利的初始化方法 类的继承特点语法格式重写父类方法super关…

SimpleDateFormat类.Java

目录 1.1构造方法 1.2格式规则 1.3常用方法 1.4练习1&#xff08; 出生日期&#xff09; 1.5练习2(秒杀活动) java.text.SimpleDateFormat 是日期/时间格式化类&#xff0c;我们通过这个类可以帮我们完成日期和文本之间的转换,也就是可以在Date对象与String对象之间进行来…

机器学习理论基础—集成学习(1)

机器学习理论基础—集成学习 个体与集成 集成学习通过构建并结合多个学习器来完成学习任务&#xff0c;有时也称为多分类系统等。 分类&#xff1a; 根据集成学习中的个体学习器的不同可以分为同质集成&#xff08;集成的学习器相同例如全部是决策树&#xff09;&#xff0c…
最新文章