1. 安装debootstrap
ubuntu操作系统:apt install debootstrap
centos操作系统:yum install debootstrap
2. 构建基础Ubuntu的rootfs
mkdir /mnt/rootfs
debootstrap --verbose --arch=amd64 bionic /mnt/rootfs http://mirrors.aliyun.com/ubuntu
说明:bionic为ubuntu代号,/mnt/rootfs为存放rootfs目录
3. 配置rootfs
#切换根
chroot .
#安装依赖包
apt-get -y update
apt-get -y upgrade
apt-get -y install vim locales iproute2 gzip curl sudo tar zip unzip telnet openssl gcc make openssh-server openssh-client
#创建用户
useradd -m dongfeng
echo "root:baicells" | chpasswd
echo "dongfeng:baicells" | chpasswd
#配置sshd
mkdir /run/sshd
mkdir /var/run/sshd
sshd -D
echo UseDNS no >> /etc/ssh/sshd_config
#其他配置
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
dpkg-reconfigure locales
rm -Rf /tmp/* && apt clean
#清理系统
rm -rf boot/ dev/ media/ mnt/ proc/ srv/ sys/echo > root/.viminfo
echo > root/.bash_history
echo > root/.viminfo
#切换根
exit
4. 导入docker
tar --numeric-owner -czvf ../Ubuntu1804-baseimages-20200323.tar.gz *
docker import Ubuntu1804-baseimages-20200323.tar.gz ubuntu:18.04
5. docker环境下启动ssh命令
/usr/sbin/sshd -D