Last active
August 29, 2015 14:00
-
-
Save zircote/11222801 to your computer and use it in GitHub Desktop.
My Docker Cheat Shit erm Sheet
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
#/bin/bash | |
# This is my collection of docker shit as I try to fit it all into my head. | |
# Feel free to add | |
### Runs the Registry Container | |
docker run -d -p 5000:5000 -v /etc/docker:/registry-conf -e DOCKER_REGISTRY_CONFIG=/registry-conf/config.yaml registry | |
### Removes Stopped Containers | |
docker rm -f $(docker ps -a -q) | |
### Removes untagger Containers | |
docker rmi $(docker images | grep "^<none>" | awk '{print $3}') | |
### Yum based docker container maker | |
# curl curl https://github.com/dotcloud/docker/blob/master/contrib/mkimage-yum.sh -o mkimage-yum.sh | |
### Pull all images in current local | |
for i in $(docker images|tail -n +2|awk '{print $1}":"{print $2}'); do docker pull $i; done | |
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
#!/usr/bin/env bash | |
# Create a base Amazon Linux Docker image. | |
usage() { | |
cat <<EOOPTS | |
$(basename $0) [OPTIONS] <name> | |
OPTIONS: | |
-y <yumconf> The path to the yum config to install packages from. The | |
default is /etc/yum.conf. | |
EOOPTS | |
exit 1 | |
} | |
# option defaults | |
yum_config=/etc/yum.conf | |
while getopts ":y:h" opt; do | |
case $opt in | |
y) | |
yum_config=$OPTARG | |
;; | |
h) | |
usage | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
name=$1 | |
if [[ -z $name ]]; then | |
usage | |
fi | |
#-------------------- | |
target=$(mktemp -d --tmpdir $(basename $0).XXXXXX) | |
set -x | |
mkdir -m 755 ${target}/dev | |
mknod -m 600 ${target}/dev/console c 5 1 | |
mknod -m 600 ${target}/dev/initctl p | |
mknod -m 666 ${target}/dev/full c 1 7 | |
mknod -m 666 ${target}/dev/null c 1 3 | |
mknod -m 666 ${target}/dev/ptmx c 5 2 | |
mknod -m 666 ${target}/dev/random c 1 8 | |
mknod -m 666 ${target}/dev/tty c 5 0 | |
mknod -m 666 ${target}/dev/tty0 c 4 0 | |
mknod -m 666 ${target}/dev/urandom c 1 9 | |
mknod -m 666 ${target}/dev/zero c 1 5 | |
yum -c "$yum_config" --installroot=${target} --setopt=tsflags=nodocs \ | |
--setopt=group_package_types=mandatory -y groupinstall Core | |
yum -c "$yum_config" --installroot=${target} -y clean all | |
cat > ${target}/etc/sysconfig/network <<EOF | |
NETWORKING=yes | |
HOSTNAME=localhost.localdomain | |
EOF | |
rm -rf ${target}/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive} | |
rm -rf ${target}/usr/share/{man,doc,info,gnome/help} | |
rm -rf ${target}/usr/share/cracklib | |
rm -rf ${target}/usr/share/i18n | |
rm -rf ${target}/sbin/sln | |
rm -rf ${target}/etc/ld.so.cache | |
rm -rf ${target}/var/cache/ldconfig/* | |
cp /etc/yum.repos.d/* ${target}/etc/yum.repos.d/ | |
version= | |
if [ -r ${target}/etc/system-release ]; then | |
version="$(sed 's/^[^0-9\]*\([0-9.]\+\).*$/\1/' ${target}/etc/system-release)" | |
fi | |
if [ -z "$version" ]; then | |
echo >&2 "warning: cannot autodetect OS version, using '$name' as tag" | |
version=$name | |
fi | |
tar --numeric-owner -c -C ${target} . | docker import - $name:$version | |
docker run -i -t $name:$version echo success | |
rm -rf ${target} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment