Last active
August 28, 2025 22:51
-
-
Save nsticco/10abb16a9a708788406c65e0b71cb170 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # This script will bootstrap Ubuntu with Docker | |
| # Customize the script by passing values to the named parameters below, e.g. | |
| # ./bootstrap-ubuntu-docker.sh --user ec2-user | |
| use_current_user=${use_current_user:-true} | |
| user=${user:-ubuntu} | |
| wsl=${wsl:-false} | |
| keygen=${keygen:-true} | |
| docker_compose=${docker_compose:-2.29.1} | |
| while [ $# -gt 0 ]; do | |
| if [[ $1 == *"--"* ]]; then | |
| param="${1/--/}" | |
| declare $param="$2" | |
| fi | |
| shift | |
| done | |
| ############################################################################### | |
| echo "Removing Docker conflicts if present..." | |
| sudo apt-get -y remove docker docker-engine docker.io containerd runc | |
| echo "Setting up the Docker repo..." | |
| sudo apt -y install apt-transport-https ca-certificates curl software-properties-common | |
| curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \ | |
| sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg --yes | |
| echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \ | |
| https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \ | |
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
| echo "Installing Docker..." | |
| sudo apt-get -y update | |
| sudo apt-get -y install docker-ce docker-ce-cli containerd.io | |
| echo "Installing Docker Compose..." | |
| sudo curl -L "https://github.com/docker/compose/releases/download/v${docker_compose}/docker-compose-$(uname -s)-$(uname -m)" \ | |
| -o /usr/local/bin/docker-compose | |
| sudo chmod +x /usr/local/bin/docker-compose | |
| echo "Adjusting user permissions..." | |
| sudo groupadd docker | |
| if [ $use_current_user = true ] ; then | |
| sudo usermod -aG docker "$(whoami)" | |
| else | |
| sudo usermod -aG docker $user | |
| fi | |
| echo "Updating and cleaning up after bootstrapping..." | |
| sudo apt-get -y update | |
| sudo apt-get -y autoremove | |
| sudo apt-get -y clean | |
| if ! [ $wsl = true ] ; then | |
| echo "Setting Docker to run at boot..." | |
| sudo systemctl enable docker | |
| fi | |
| if [ $keygen = true ] ; then | |
| echo "Checking if ssh key already exists..." | |
| if [ ! -f ~/.ssh/id_rsa ] ; then | |
| echo "Generating a new SSH key..." | |
| ssh-keygen -q -t rsa -b 4096 -N "" -C "$(whoami)@$(hostname) on $(cat /etc/os-release)" \ | |
| -f ~/.ssh/id_rsa <<<y 2>&1 >/dev/null | |
| else | |
| echo "Key already exists" | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment