Skip to content

Instantly share code, notes, and snippets.

@ReedD
Last active July 18, 2024 16:04
Show Gist options
  • Save ReedD/a46c10ccce5af12c8d5f to your computer and use it in GitHub Desktop.
Save ReedD/a46c10ccce5af12c8d5f to your computer and use it in GitHub Desktop.
User data for EC2 to set up Docker and Compose (Fig) for ec2-user
#!/bin/sh
export PATH=/usr/local/bin:$PATH;
yum update
yum install docker -y
service docker start
# Docker login notes:
# - For no email, just put one blank space.
# - Also the private repo protocol and version are needed for docker
# to properly setup the .dockercfg file to work with compose
docker login --username="someuser" --password="asdfasdf" --email=" " https://example.com/v1/
mv /root/.dockercfg /home/ec2-user/.dockercfg
chown ec2-user:ec2-user /home/ec2-user/.dockercfg
usermod -a -G docker ec2-user
curl -L https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
chown root:docker /usr/local/bin/docker-compose
cat <<EOF >/home/ec2-user/docker-compose.yml
nginx:
image: nginx
ports:
- "80:80"
EOF
chown ec2-user:ec2-user /home/ec2-user/docker-compose.yml
/usr/local/bin/docker-compose -f /home/ec2-user/docker-compose.yml up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment