Skip to content

Instantly share code, notes, and snippets.

@17twenty
Last active March 23, 2017 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 17twenty/9c59da94e6069ff93b457f7d476cb5dc to your computer and use it in GitHub Desktop.
Save 17twenty/9c59da94e6069ff93b457f7d476cb5dc to your computer and use it in GitHub Desktop.
Terraform Docker Injection - You can override the docker config this way - useful for custom BIP / CIDRs
...
# Fetch the AWS ECS Optimized Linux AMI. Note that if you've never launched this AMI before, you have to accept the
# terms and conditions on this webpage or the EC2 instances will fail to launch:
# https://aws.amazon.com/marketplace/pp/B00U6QTYI2
data "aws_ami" "ecs" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn-ami-*-amazon-ecs-optimized"]
}
}
data "template_file" "ecs_config" {
template = "${file("user_data.sh")}"
vars {
cluster_name = "${var.ecs_cluster_name}"
username = "${var.username}"
password = "${var.password}"
}
}
...
#!/bin/bash
echo "ECS_CLUSTER=${cluster_name}" >> /etc/ecs/ecs.config
echo "ECS_ENGINE_AUTH_TYPE=docker" >> /etc/ecs/ecs.config
echo "ECS_ENGINE_AUTH_DATA={\"custom.repo.internal.local:9090\":{\"username\":\"${username}\",\"password\":\"${password}\"}}" >> /etc/ecs/ecs.config
cat <<EOF > /etc/sysconfig/docker
# The max number of open files for the daemon itself, and all
# running containers. The default value of 1048576 mirrors the value
# used by the systemd service unit.
DAEMON_MAXFILES=1048576
# Additional startup options for the Docker daemon, for example:
# OPTIONS="--ip-forward=true --iptables=true"
# By default we limit the number of open files per container
OPTIONS="--default-ulimit nofile=1024:4096 --bip=192.168.200.1/24"
# How many seconds the sysvinit script waits for the pidfile to appear
# when starting the daemon.
DAEMON_PIDFILE_TIMEOUT=10
EOF
# Restart the agent due to the fact that bootstrapping order is weird!
service docker restart
docker start ecs-agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment