Skip to content

Instantly share code, notes, and snippets.

@jgautheron
Forked from cjbottaro/overlay.sh
Last active May 31, 2017 12:13
Show Gist options
  • Save jgautheron/5a04e7d84a12010000b3a610b5316cd0 to your computer and use it in GitHub Desktop.
Save jgautheron/5a04e7d84a12010000b3a610b5316cd0 to your computer and use it in GitHub Desktop.
Convert ECS Optimized AMI to use overlay/overlay2
set -e
# Stop the docker daemon
/etc/init.d/docker stop
# Configure ECS Agent
# http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html
# http://docs.aws.amazon.com/AmazonECS/latest/developerguide/automated_image_cleanup.html
cat > /etc/ecs/ecs.config << "EOF"
ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION=1h
ECS_NUM_IMAGES_DELETE_PER_CYCLE=100
EOF
# Install some packages
yum update -y
yum install -y vim-enhanced curl wget epel-release
# Needed for docker's completion
yum install -y bash-completion --enablerepo=epel
# Upgrade to Docker 17.05.0-ce
wget https://get.docker.com/builds/Linux/x86_64/docker-17.05.0-ce.tgz
tar xzf docker-17.05.0-ce.tgz
cp docker/docker* /usr/bin
cp docker/completion/bash/docker /etc/bash_completion.d/
rm -rf docker*
# Let everyone access bind mounted /var/run/docker.sock
sed -i '$ d' /etc/init.d/docker # Remove last line which was: exit $?
cat >> /etc/init.d/docker << "EOF"
retval=$?
chmod 666 /var/run/docker.sock
exit $retval
EOF
# Use good ole port 4242 for ssh
sed -i 's/#Port 22/Port 4242/' /etc/ssh/sshd_config
# Get rid of devicemapper defs
dmsetup remove_all
# Reset the disk
dd if=/dev/zero of=/dev/xvdcz bs=512 count=128
# Remove all docker data
rm -rf /var/lib/docker/*
# Remove ecs data
rm -rf /var/lib/ecs/data/* /var/cache/ecs/*
# Remove cloud-init stuff so that it runs again
rm -rf /var/lib/cloud/*
# Remove logs
rm -rf /var/log/cloud-init* /var/log/docker /var/log/ecs/*
# Don't need this
cat > /etc/sysconfig/docker-storage-setup << "EOF"
echo "Not needed with overlay, contents removed"
exit 1
EOF
# Setup docker to use overlay
cat > /etc/sysconfig/docker-storage << "EOF"
DOCKER_STORAGE_OPTIONS="--storage-driver=overlay"
EOF
# Setup cloud init to prep disks for docker to use overlay
cat > /etc/cloud/cloud.cfg.d/90_ecs.cfg << "EOF"
#cloud-config
cloud_init_modules:
- bootcmd
cloud_config_modules:
- mounts
system_info:
default_user:
groups: [ "wheel", "docker" ]
bootcmd:
- [ cloud-init-per, once, docker_overlay_fs, mkfs, -t, ext4, -L, docker, -i, 4096, /dev/xvdcz ]
# This doesn't seem to work, hence using the bootcmd above instead.
# fs_setup:
# - label: docker
# filesystem: ext4
# device: /dev/xvdcz
# partition: none
# cmd: mkfs -t %(FILESYSTEM)s -L %(LABEL)s -i 4096 %(DEVICE)s
mounts:
- [ /dev/xvdcz, /var/lib/docker/overlay ]
EOF
# Start the docker daemon
/etc/init.d/docker start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment