docker 容器内默认安装的指令非常少,cdlscat 等是有的,但其他的如 lesspspingvim 等指令是缺少的。cat /etc/issue 看了一下(lsb_release -a 指令缺失),安装的 nginx、php、mysql、redis 等服务容器内部都是:

Debian GNU/Linux 11 \n \l

部分可能版本是 10,包括 ubuntu 都可以使用 apt 指令快速安装。搜集了一下相关指令安装做一个记录。

1. ping

之前需要确认容器是否可以互相 ping 通,所以遇到了 docker 容器中 ping 找不到,安装 ping 指令

apt install -y iputils-ping

也有看到说是 inetutils-ping 这个没试过,但 apt 查询是存在的。

2. ps

习惯了使用 ps 查询进程,这也是必要的

apt-get install procps

3. vim

apt-get install vim

4. netstat

netstat 可以查询一些特定端口服务

apt-get install net-tools

5. nmap

nmap 端口扫描工具,方便了解本地或其他服务器开放的端口

apt install nmap

6. tab 自动完成

debain 默认的 shell 脚本解析器是 dash,需要改成 bash

这个不是指令,主要作用是能够在 docker 容器中使用 tab 自动完成指令或路径、文件名

另外发现,启用 bash 解释器后,history、source 指令也可以使用

# ls -s /bin/sh
lrwxrwxrwx 1 root root 4 Dec 20  2021 /bin/sh -> dash
# dpkg-reconfigure dash
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Configuring dash
----------------

The system shell is the default command interpreter for shell scripts.

Using dash as the system shell will improve the system's overall performance. It does not alter the shell presented to interactive
users.

Use dash as the default system shell (/bin/sh)? [yes/no] no
Removing 'diversion of /bin/sh to /bin/sh.distrib by dash'
Adding 'diversion of /bin/sh to /bin/sh.distrib by bash'
Removing 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'
Adding 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by bash'

重启容器,再次进入 Terminal 中,命令行前缀变成了 sh-5.0# 。此时 tab 可以自动完成了。

当前为 docker 20.10.23 最新版,并没有像 解决ubuntu docker容器命令tab无法自动补全问题 里需要安装 bash-completion

7. 11

ll 属于别名指令,等于 ls -l

echo "alias ll='ls -l'" >> ~/.bashrc && source ~/.bashrc
文章目录