Last active
December 27, 2015 07:09
-
-
Save hagix9/7286981 to your computer and use it in GitHub Desktop.
Docker0.6.6 Install for CentOS6.4
reference: https://github.com/sciurus/docker-rhel-rpm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SELinux setting | |
sed -i.bak "s/\(^SELINUX=\).*/\1disabled/" /etc/selinux/config | |
#IPv4Forwarding setting | |
sed -i.bak "s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/" /etc/sysctl.conf | |
######################################################################################## | |
# add Repository | |
rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm | |
# buildtool install | |
yum install spectool git mock -y | |
# user add for mock command | |
adduser -m -G mock build | |
# su build user | |
su - build | |
# build docker kernel and lxc and doker | |
git clone https://github.com/sciurus/docker-rhel-rpm.git | |
cd docker-rhel-rpm | |
# build docker rpm | |
cp -a lxc-docker/lxc-docker.spec lxc-docker/lxc-docker.spec_bak | |
sed -i 's/0.6.5/0.6.6/' lxc-docker/lxc-docker.spec | |
spectool -g -C lxc-docker lxc-docker/lxc-docker.spec | |
mock -r epel-6-x86_64 --buildsrpm --spec lxc-docker/lxc-docker.spec --sources lxc-docker --resultdir output | |
mock -r epel-6-x86_64 --rebuild --resultdir output output/lxc-docker-0.6.6-1.el6.src.rpm | |
# build lxc rpm | |
spectool -g -C lxc lxc/lxc.spec | |
mock -r epel-6-x86_64 --buildsrpm --spec lxc/lxc.spec --sources lxc --resultdir output | |
mock -r epel-6-x86_64 --rebuild --resultdir output output/lxc-0.8.0-3.el6.src.rpm | |
# build kernel rpm | |
###workaround### | |
cp -a kernel-ml-aufs/kernel-ml-aufs-3.10.spec kernel-ml-aufs/kernel-ml-aufs-3.10.spec_bak | |
sed -i '/include\/linux\/aufs_type.h/d' kernel-ml-aufs/kernel-ml-aufs-3.10.spec | |
sed -i '/aufs3-proc_map.patch/d' kernel-ml-aufs/kernel-ml-aufs-3.10.spec | |
sed -i '319a patch -p 1 < ../%{AUFSver}/aufs3-mmap.patch' kernel-ml-aufs/kernel-ml-aufs-3.10.spec | |
################ | |
spectool -g -C kernel-ml-aufs kernel-ml-aufs/kernel-ml-aufs-3.10.spec | |
git clone git://git.code.sf.net/p/aufs/aufs3-standalone -b aufs3.10 | |
###workaround### | |
cp -a aufs3-standalone aufs3-standalone_5f8ee4 | |
cd aufs3-standalone_5f8ee4 | |
git checkout 5f8ee4 | |
cp -a Documentation ../aufs3-standalone | |
cp -a fs/aufs/* ../aufs3-standalone/fs/aufs/ | |
cp -a include/linux/ ../aufs3-standalone/include/ | |
cd .. | |
################ | |
pushd aufs3-standalone | |
git archive aufs3.10 > ../kernel-ml-aufs/aufs3-standalone.tar | |
popd | |
mock -r epel-6-x86_64 --buildsrpm --spec kernel-ml-aufs/kernel-ml-aufs-3.10.spec --sources kernel-ml-aufs --resultdir output | |
mock -r epel-6-x86_64 --rebuild --resultdir output output/kernel-ml-aufs-3.10.11-1.el6.src.rpm | |
exit | |
# install docker kernel lxc | |
cd /home/build/docker-rhel-rpm/output | |
yum localinstall --nogpgcheck kernel-ml-aufs-3.10.11-1.el6.x86_64.rpm lxc-0.8.0-3.el6.x86_64.rpm lxc-libs-0.8.0-3.el6.x86_64.rpm lxc-docker-0.6.5-1.el6.x86_64.rpm -y | |
######################################################################################## | |
# download and install output rpm | |
wget https://dl.dropboxusercontent.com/u/3185206/lxc-docker-rpm/kernel-ml-aufs-3.10.11-1.el6.x86_64.rpm | |
wget https://dl.dropboxusercontent.com/u/3185206/lxc-docker-rpm/lxc-libs-0.8.0-3.el6.x86_64.rpm | |
wget https://dl.dropboxusercontent.com/u/3185206/lxc-docker-rpm/lxc-0.8.0-3.el6.x86_64.rpm | |
wget https://dl.dropboxusercontent.com/u/3185206/lxc-docker-rpm/lxc-docker-0.6.5-1.el6.x86_64.rpm | |
yum localinstall --nogpgcheck kernel-ml-aufs-3.10.11-1.el6.x86_64.rpm lxc-0.8.0-3.el6.x86_64.rpm lxc-libs-0.8.0-3.el6.x86_64.rpm lxc-docker-0.6.5-1.el6.x86_64.rpm -y | |
# cgroup setting | |
chkconfig cgconfig off | |
cp -a /etc/fstab /etc/fstab_bak | |
echo "none /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab | |
# grub setting | |
sed -i 's/default=1/default=0/' /boot/grub/grub.conf | |
# docker init script add | |
cat << 'EOF' > /etc/init.d/lxc-docker | |
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: lxc-docker | |
# Required-Start: $syslog $remote_fs | |
# Required-Stop: $syslog $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Linux container runtime | |
# Description: Linux container runtime | |
### END INIT INFO | |
DOCKER=/usr/bin/docker | |
# Check lxc-docker is present | |
[ -x $DOCKER ] || (log_failure_msg "lxc-docker not present"; exit 1) | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
# Get lsb functions | |
. /etc/init.d/functions | |
check_root_id () | |
{ | |
if [ "$(id -u)" != "0" ]; then | |
log_failure_msg "LXC Docker must be run as root"; exit 1 | |
fi | |
} | |
case "$1" in | |
start) | |
check_root_id || exit 1 | |
mount | grep cgroup >/dev/null || mount -t cgroup none /sys/fs/cgroup | |
daemon "$DOCKER" -d & | |
;; | |
stop) | |
check_root_id || exit 1 | |
mount | grep cgroup >/dev/null && umount /sys/fs/cgroup | |
kill $(echo $(ps -ef |grep docker | egrep -v "vi|grep" | awk '{print $2}')) | |
;; | |
restart) | |
check_root_id || exit 1 | |
docker_pid=`pgrep -f "$DOCKER -d"` | |
[ -n "$docker_pid" ] && /etc/init.d/lxc-docker stop | |
/etc/init.d/lxc-docker start | |
;; | |
force-reload) | |
check_root_id || exit 1 | |
/etc/init.d/lxc-docker restart | |
;; | |
status) | |
docker_pid=`pgrep -f "$DOCKER -d"` | |
if [ -z "$docker_pid" ] ; then | |
echo "lxc-docker not running" | |
else | |
echo "lxc-docker running (pid $docker_pid)" | |
fi | |
;; | |
*) | |
echo "Usage: /etc/init.d/lxc-docker {start|stop|restart|status}" | |
exit 1 | |
;; | |
esac | |
exit 0 | |
EOF | |
chmod 755 /etc/init.d/lxc-docker | |
chkconfig --add lxc-docker | |
# iptables settings | |
cat << 'EOF' > /etc/sysconfig/iptables | |
*nat | |
:PREROUTING ACCEPT [3:156] | |
:INPUT ACCEPT [0:0] | |
:OUTPUT ACCEPT [0:0] | |
:POSTROUTING ACCEPT [0:0] | |
:DOCKER - [0:0] | |
[0:0] -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER | |
[0:0] -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER | |
[0:0] -A POSTROUTING -s 172.17.0.0/16 ! -d 172.17.0.0/16 -j MASQUERADE | |
COMMIT | |
#*filter | |
:INPUT ACCEPT [0:0] | |
:FORWARD ACCEPT [0:0] | |
:OUTPUT ACCEPT [0:0] | |
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | |
-A INPUT -p icmp -j ACCEPT | |
-A INPUT -i lo -j ACCEPT | |
-A INPUT -i docker0 -j ACCEPT | |
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT | |
-A INPUT -j REJECT --reject-with icmp-host-prohibited | |
-A FORWARD -i docker0 -j ACCEPT | |
#-A FORWARD -j REJECT --reject-with icmp-host-prohibited | |
COMMIT | |
EOF | |
chkconfig iptables on | |
reboot | |
# enjoy docker | |
docker pull centos | |
docker run -i -t centos /bin/bash | |
# use for normal user setting | |
usermod -G docker user | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment