Skip to content

Instantly share code, notes, and snippets.

@Coinhexa
Created July 12, 2023 13:48
Show Gist options
  • Select an option

  • Save Coinhexa/4ebd5220b941cbaba0099939d66e6426 to your computer and use it in GitHub Desktop.

Select an option

Save Coinhexa/4ebd5220b941cbaba0099939d66e6426 to your computer and use it in GitHub Desktop.
How to install docker and docker-compose for Amazon Linux 2 as user data script inside AWS EC2
#!/bin/sh
# https://stackoverflow.com/a/75036284/5371505
# Update all dependencies
yum update -y
# Install docker and git
yum install docker git -y
# Give user permissions
usermod -a -G docker ec2-user
id ec2-user
newgrp docker
# Launch docker on instance start
systemctl enable docker.service
systemctl start docker.service
docker info
# Install docker-compose
curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version
cd /home/ec2-user
git clone -b main <your-project-repo>
chown -R ec2-user:ec2-user <your-project-repo>
cd <your-project-repo>
docker-compose -f "<your-project-repo>/<your-dockerfile-directory>/docker-compose.yml" up -d --build && docker-compose -f "<your-project-repo>/<your-dockerfile-directory>/docker-compose.yml" logs --follow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment