Skip to content

Instantly share code, notes, and snippets.

@junmakii
Created May 30, 2018 08:16
Show Gist options
  • Select an option

  • Save junmakii/4c3b9970141faa703a6c6be6c2ee1d6b to your computer and use it in GitHub Desktop.

Select an option

Save junmakii/4c3b9970141faa703a6c6be6c2ee1d6b to your computer and use it in GitHub Desktop.
case ${1} in
init)
cat /etc/yum.conf /data/yum.conf.bak
cat /etc/yum.conf | sed 's/cachedir=.*/cachedir=\/opt\/yum-cache/' | sed 's/keepcache=0/keepcache=1/' > /tmp/yum.conf
cp /tmp/yum.conf /etc/yum.conf
yum makecache
yum update -y
yum install -y epel-release
yum install -y "@Development Tools"
yum install -y bash-completion bash-completion-extra
yum install -y python python-devel python-setuptools python-pip
;;
desktop)
yum install -y "@X Window System"
;;
esac
#!/bin/bash
if [[ $# -lt 2 ]]; then
echo "${0} <action> <name>"
exit 1
fi
NAME=${2}
VERSION=0.1
case ${1} in
init)
sudo docker pull "centos:7"
sudo docker tag "centos:7" "${NAME}:${VERSION}"
sudo docker run -v $(pwd):/opt/data \
-v ${HOME}/workspace:/data \
-v $(pwd)/yum-cache:/opt/yum-cache \
--name ${USER}-$(uuidgen) \
-it "${NAME}:${VERSION}" \
bash /opt/data/centos-setup.sh init
sudo ${0} commit ${NAME}
;;
up)
[ -z "$(sudo docker ps -q --filter=ancestor=${NAME}:${VERSION} | head -n 1)" ] && sudo ${0} run ${NAME} || exit 0
;;
run)
sudo docker run -d --privileged \
-v ${HOME}/workspace:/data \
-v $(pwd):/opt/data \
-v $(pwd)/yum-cache:/opt/yum-cache \
$(bash -c "for i in {20000..20100}; do echo \"-p \${i}:\${i}\"; done | tr '' '\n'") -e DISPLAY=${DISPLAY} \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--name ${USER}-$(uuidgen) \
"${NAME}:${VERSION}" /sbin/init || exit 0
;;
commit)
sudo docker commit $(sudo docker ps -q -a --filter=ancestor=${NAME}:${VERSION} | head -n 1) "${NAME}:${VERSION}"
;;
shell)
sudo docker exec -it $(sudo docker ps -q --filter=ancestor=${NAME}:${VERSION} | head -n 1) bash
;;
stop)
sudo docker ps -q --filter=ancestor=${NAME}:${VERSION} | awk "{print \"sudo docker stop -t 5\", \$1}" | sudo bash
;;
clean)
sudo docker system prune -f
;;
save)
sudo docker save -o ${NAME}.docker.img ${NAME}:${VERSION}
;;
load)
sudo docker load -i ${NAME}.docker.img
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment