Skip to content

Instantly share code, notes, and snippets.

@nithu0115
Last active December 19, 2018 03:48
Show Gist options
  • Save nithu0115/f8deed67bf365cb9f4e49014679e3303 to your computer and use it in GitHub Desktop.
Save nithu0115/f8deed67bf365cb9f4e49014679e3303 to your computer and use it in GitHub Desktop.
Amazon Linux2 - Using a secondary volume for docker overlay2 filesystem
## ECS AMI - Amzn Linux2 - Using a secondary volume for docker overlay2 filesystem
#### — Replace the device names with appropriate names, as they vary depending on Instance type and volume type - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html
[1] https://github.com/docker/docker-ce/blob/v18.06.1-ce/components/packaging/rpm/systemd/docker.service#L4
[2] https://github.com/aws/amazon-ecs-init/blob/master/packaging/amazon-linux-ami/ecs.service#L19
UserData for 'c5d' with an instance store as the secondary volume
#!/bin/bash -x
## disable systemd from starting docker and ecs during cloud-init
systemctl disable --now --no-block ecs.service
systemctl disable --now --no-block docker.service
## Setup ext4 filesystem for docker overlay2 and mount under /mnt
mkfs.ext4 /dev/nvme1n1
mount -t ext4 /dev/nvme1n1 /mnt
## Preserve fstab entries and persist /mnt mount settings across reboots
cp -pf /etc/fstab /etc/fstab.orig
grep '/dev/nvme1n1' /proc/mounts | tee -a /etc/fstab
## Setup docker storage options to use /mnt
echo 'DOCKER_STORAGE_OPTIONS="--data-root=/mnt"' >> /etc/sysconfig/docker-storage
## Configure ECS cluster in agent config
echo 'ECS_CLUSTER=default' >> /etc/ecs/ecs.config
## Enable services and startup docker and ecs
systemctl enable --now --no-block docker.service
systemctl enable --now --no-block ecs.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment