安装Debootstrap
ubuntu操作系统:apt install debootstrap
centos操作系统:yum install debootstrap
构建基础Ubuntu的rootfs
debootstrap --verbose --arch=amd64 xenial ubuntu16.04 http://mirrors.aliyun.com/ubuntu
说明:xenial为ubuntu代号,ubuntu16.04为存放rootfs目录
配置rootfs
chroot .
安装依赖包
apt-get -y update
apt-get -y upgrade
apt-get -y install vim locales iproute gzip curl sudo tar zip unzip telnet openssl gcc make openssh-server openssh-client
创建用户
useradd -m lykops
echo "root:1qaz2wsx" | chpasswd
echo "lykops:1qaz2wsx" | 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
退出chroot
exit
清理系统
rm -rf boot/ dev/ media/ mnt/ proc/ srv/ sys/echo > root/.viminfo
echo > root/.bash_history
echo > root/.viminfo
导入docker
tar --numeric-owner -czvf ../Ubuntu1604-baseimages-20170907.tar.gz *
docker import Ubuntu1604-baseimages-20170907.tar.gz ubuntu:16.04
docker环境下启动ssh命令
/usr/sbin/sshd -D