因为现在的环境还在CentOS5下,但新的库只有在CentOS6下才能用。然后用Docker启动完整OS,这样相对于ESX省资源一点点。
目前的环境是宿主机是ubuntu 16.04, 然后容器就 centos5 和 centos6
首先直接从官方下载相关底包
docker pull centos:5.11 docker pull centos:6.8
然后直接在底包上组安装相关软件
yum groupinstall ...
上面直接组安装法对5.11没问题, 6.8就是没办法折腾。6.8上只要这样安装,再启动容器,发现会卡在
sulogin 这个进程上,然后就没反应了(另外,rc.sysinit 这个进程应该运行一下就消失的却一直都在)。查询了一下这个进程是单用户登录用的,然后只要有这个进程就没办法SSH了。
然后我是按下面的包顺序安装的。
# 先安装的SSH,安装一个 commit 一次, 一行装一次 openssh-server # 下面的是 Base 包里的 abrt-addon-ccpp abrt-addon-kerneloops abrt-addon-python abrt-cli acpid alsa-utils at authconfig b43-fwcutter bc biosdevname blktrace bridge-utils centos-indexhtml cpuspeed crontabs cryptsetup-luks cyrus-sasl-plain dbus fprintd-pam hunspell hunspell-en irqbalance ledmon libaio logrotate lsof lvm2 man man-pages man-pages-overrides microcode_ctl mlocate mtr nano ntp ntpdate ntsysv openssh-clients pam_passwdqc pciutils pcmciautils pinfo pm-utils prelink psacct rdate readahead rfkill rng-tools rsync scl-utils setserial setuptool smartmontools sos strace sysstat system-config-firewall-tui system-config-network-tui systemtap-runtime tcpdump tcsh time tmpwatch traceroute unzip vconfig vim-enhanced virt-what wget words xz yum-plugin-security yum-utils zip bind-utils # 下面的是开发工具组 直接 yum groupinstall ... "Development tools" # 下面这些是 Desktop, "X windows", 还有附加开发中的东西, GConf2-devel NetworkManager NetworkManager-gnome alsa-lib-devel alsa-plugins-pulseaudio at-spi audit-libs-devel binutils-devel boost-devel bzip2-devel control-center control-center-extra cyrus-sasl-devel dbus-glib-devel elfutils-devel elfutils-libelf-devel eog evolution-data-server-devel firstboot gdm gdm-plugin-fingerprint gdm-user-switch-applet glx-utils gnome-applets gnome-desktop-devel gnome-keyring-devel gnome-media gnome-packagekit gnome-panel gnome-power-manager java-1.6.0-openjdk-devel perl-devel mysql-devel python-devel perl-ExtUtils-MakeMaker sqlite-devel libcurl-devel libacl-devel libattr-devel libcanberra-devel libcap-ng-devel libcgroup-devel libgnome-devel libnotify-devel librsvg2-devel libsoup-devel pygtk2-devel readline-devel tbb-devel vnc-server nscd pam_ldap vsftpd xdg-user-dirs-gtk xorg-x11-drivers xorg-x11-server-Xorg xorg-x11-server-utils xorg-x11-utils xorg-x11-xauth xorg-x11-xinit xvattr yelp polkit-devel gnome-terminal polkit-gnome spice-vdagent vino wacomexpresskeys wdaemon notification-daemon
最后还有下面这几这个包只要安装就会卡在 sulogin, 暂时不知道乍整
nautilus gok hmaccalc gvfs-devel gnome-vfs2-smb gvfs-archive gvfs-fuse gvfs-smb
引导完整系统官方是不推荐这样做的,毕竟Docker是轻量级的,这样违背了他的初衷了。
要引导完整系统run后面的参数就是 /sbin/init
在安装好 autofs 后,想启动它发现提示:
Starting automount: automount: test mount forbidden or incorrect kernel protocol version, kernel protocol version 5.00 or above required. [FAILED]
搜索后发现原来是权限不够。
直接在 run 时加上 --privileged 即可,如:
docker run --rm --privileged -p 3000:22 -v /root/centos6:/root centos6/d1103:D /sbin/init
容器启动后,在宿主机发现 agetty 进程CPU占用100%,再次放狗,解决办法如下
systemctl list-units *getty* systemctl stop [email protected] #主要是这个停止后就OK systemctl stop system-getty.slice systemctl stop getty.target
另外容器还要固定IP,然后用的macvlan办法,写了一个小脚本用来启动容器并设置IP
#!/bin/bash # start container and setting container IP address if [[ $# -ne 3 ]] then echo "./script.sh image_name ip_dev_name container_ip" echo "" echo "./script.sh centos5/new:A enp4s0 192.168.1.6/24" echo "" exit fi config=/local_home/docker/config docker run -d --privileged -v $config/${1%/*}:/root $1 /sbin/init docker_pid=$(docker inspect $(docker ps | awk -vt=$2 ‘NR>1&&$2==t{print $1}‘) 2>/dev/null | awk ‘$1~/Pid\"/{print +$2}‘) if [[ -z "$docker_pid" ]] then echo "docker container name not found" exit fi if [[ `ip link | awk -vdev=$2 ‘$2==dev":"{a=1}END{print a}‘` -ne 1 ]] then echo "ip dev name error" exit fi ip link add "$2".d link "$2" type macvlan mode bridge ip link set netns "$docker_pid" "${2}.d" nsenter -t "$docker_pid" -n ip link set "${2}.d" up nsenter -t "$docker_pid" -n ip route del default nsenter -t "$docker_pid" -n ip addr add "$3" dev "${2}.d" nsenter -t "$docker_pid" -n ip route add default via `ip r | awk ‘/default/{print $3}‘` dev "${2}.d" # 进入容器 # nsenter --target=$docker_pid --net --mount --uts --pid
时间: 2024-10-26 19:06:21