docker exec -it 容器ID /bin/bash

进入容器内部,容器内部基本上很多命令都被删除,例如 ping、curl、vim、vi、ip。如果有在容器内部调试的需求,没有这些基础命令是非常难受的。

在制作镜像时,都会使用一个基本的系统镜像来构建,基础镜像一般分为 redhat系列 和 debian系列。

1:Debian系列

绝大部分 debian 系列默认并不支持 https apt 源,需要安装apt-transport-httpsca-certificates才支持。

清华源并不支持 http,只有阿里云中科大的 apt源 才支持。

# 配置 apt 源
 sed -i '/^deb\|^deb-src/ s/^/#/' /etc/apt/sources.list
 cat > /etc/apt/sources.list.d/aliyun.list << EOF
 deb http://mirrors.aliyun.com/debian/ `grep -oP 'VERSION_CODENAME=\K\w+.*' /etc/os-release` main non-free contrib
 deb-src http://mirrors.aliyun.com/debian/ `grep -oP 'VERSION_CODENAME=\K\w+.*' /etc/os-release` main non-free contrib
 EOF
 apt clean all
 apt update
 
 # 安装必备命令
 apt -y install vim apt-transport-https ca-certificates iputils-ping net-tools iproute2 curl wget

2:Redhat系列

将redhat 系列作为系统镜像相比 debian 系列要少一些。

目前还没遇到,遇到再说。