The Subnet Blog

My User Data Recipe for an AWS EC2 Instance launched with Docker

I’m using an Ubuntu server instance on EC2 and run the below script as user data on initial launch . . . .

I need to manually update the Docker compose URL/version in the script below – – Still need to figure out how to automate that.

User Data to launch Ubuntu instance with Docker installed

# Install docker
apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL | sudo apt-key add -
add-apt-repository \
   "deb [arch=amd64] \
   $(lsb_release -cs) \
apt-get update
apt-get install -y docker-ce
usermod -aG docker ubuntu

# Install docker-compose
curl -L$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

# To check: grep "cloud-init\[" /var/log/syslog
#       OR: less /var/log/cloud-init-output.log

# Manually add user to docker group
# sudo usermod -aG docker $USER

Drop a comment

Your email address will not be published. Required fields are marked *