Docker之常见FAQ记录清单

server/2024/11/24 2:20:34/

一、前言

在这里插入图片描述

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

在这里插入图片描述

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

二、问题及处理记录

dockervinano_9">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 -ydpkg-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.ppmy.cn/server/20885.html

相关文章

css文字和span在一行对不齐

1.需求背景 父盒子中有两个span&#xff0c;但是span中的文字对不齐。如下图&#xff0c;明显右边的文字偏高 处理后的效果&#xff08;已经对齐&#xff0c;图中标记的是基本的div结构&#xff09;&#xff1a; 2.该问题出现的原因&#xff1a; span1设置的高度比span2内…

eCognition 分类

目录 前言 一、阈值分类 1、创建自定义特征 2、查看对象特征值 3、阈值分类 3.1 新建类别(如果已有类别即跳过) 3.2、建立分类阈值规则 4、导出分类结果 5、附录:如果需要合并结果、按以下步骤 二、监督分类 1、方法1:利用classification算法(主要用于最邻近)…

IntelliJ IDEA个人可一直使用方法参考

IntelliJ IDEA使用方法 1.下载最新的 IDEA 2021.2.2 版本安装包 https://www.jetbrains.com/idea/download/ 2.先卸载老版本的 IDEA 3.安装新版本&#xff0c;进行激活—勾选 Evaluate for free, 点击 Evaluate&#xff0c; 先试用30天: 4.随便新建个Java工程&#xff0c;然后…

Swift字符串

在 Swift 中&#xff0c;Character 和 String 是用于处理文本数据的两个重要类型。 Character Character 是 Swift 中用于表示单个 Unicode 字符的类型。每个 Character 实例都代表一个可见的字符&#xff08;如字母、数字、标点符号等&#xff09;&#xff0c;或者一个不可见的…

物联网应用技术综合实训室解决方案

一、背景 随着物联网技术的快速发展和广泛应用&#xff0c;物联网产业已经成为新的经济增长点&#xff0c;对于推动产业升级、提高社会信息化水平具有重要意义。因此&#xff0c;培养具备物联网技术应用能力的高素质人才成为了迫切需求。 传统的教育模式往往注重理论教学&…

内网穿透及公网解析说明

内网穿透释义&#xff1a; 自己在本地搭建服务器时&#xff0c;本地网络有多种环境&#xff0c;如没有公网IP、没有路由映射权限、网络被NAT转发等情况。在需要外网访问内网服务器资源时&#xff0c;就需要用到内网穿透。内网穿透&#xff0c;即内网映射&#xff0c;内网IP地址…

Eclipse 安装 lombok 和配置

如 Eclipse 不配置的话&#xff0c;是没有办法编译 lombok 项目的。 下载 Jar 如果你项目使用的是 maven&#xff0c;那么 jar 应该下载下来了。 到 pom.xm 文件中找到有关 lombok 的依赖。 <dependency><groupId>org.projectlombok</groupId><artifac…

查看笔记本电池容量/健康状态

1. 打开命令行提示符 快捷键“win R”后输入“cmd” 2. 在命令提示符中输入命令 “powercfg /batteryreport" 并回车 3. 查看文件 最后就可以看到笔记本的电池使用报告了