Skip to content

Instantly share code, notes, and snippets.

@gonzaloplaza
Last active February 3, 2025 10:01
Show Gist options
  • Save gonzaloplaza/ff79d0593085ed14b3a5c1ba2f8f7afa to your computer and use it in GitHub Desktop.
Save gonzaloplaza/ff79d0593085ed14b3a5c1ba2f8f7afa to your computer and use it in GitHub Desktop.
Script to auto install Docker (last version) into AWS EC2/Ubuntu instance at launch time: User Data
#!/bin/bash
# Install docker
apt-get update
apt-get install -y cloud-utils apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce
usermod -aG docker ubuntu
# Install docker-compose
curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
@dowserb
Copy link

dowserb commented Apr 27, 2022

Thanks, just what I was looking for. Works well.

@fxmarty
Copy link

fxmarty commented Nov 21, 2022

Thanks!

@Izcarmt95
Copy link

thanks !

@ish-codes-magic
Copy link

I also want that when I start a new aws ec2 instance, it automatically downloads an image and run the container from that image, I can download the image, but it is not able to create the container using docker run command, can you help me with that?

@HaddarD
Copy link

HaddarD commented Sep 24, 2024

ubuntu@ip-10-0-3-119:~$ docker --version
Command 'docker' not found, but can be installed with:
sudo snap install docker # version 24.0.5, or
sudo apt install podman-docker # version 4.9.3+ds1-1ubuntu0.1
sudo apt install docker.io # version 24.0.5-0ubuntu1
See 'snap info docker' for additional versions.

I've been getting this with this one, plus any other UserData I tried to install docker with on AWS EC2 Ubuntu.
I don't understand what the issue is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment