Skip to content

Instantly share code, notes, and snippets.

@elifiner
Last active May 7, 2022 04:48
Show Gist options
  • Save elifiner/f1e19b49bf65369b82bc9d6734abc16d to your computer and use it in GitHub Desktop.
Save elifiner/f1e19b49bf65369b82bc9d6734abc16d to your computer and use it in GitHub Desktop.
Set up a bare Ubuntu box to run a Docker
#!/bin/bash
# This script should set up a bare Ubuntu box (like the one in DigitalOcean)
# with everything needed to run a Docker-based environment.
#
# To set up a fresh box, login as root and run:
#
# $ curl https://gist.githubusercontent.com/elifiner/f1e19b49bf65369b82bc9d6734abc16d/raw | sh -
USER=eli
DOCKER_COMPOSE_VERSION=1.29.2
# create user and set up ssh and sudo
adduser --disabled-password --gecos "" $USER
adduser $USER sudo
mkdir /home/$USER/.ssh
cp .ssh/authorized_keys /home/$USER/.ssh
chown -R $USER:$USER /home/$USER/.ssh
chmod 640 /etc/sudoers
echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers
# install docker and dependencies
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 apt-transport-https ca-certificates curl software-properties-common unzip
apt-get install linux-image-extra-virtual
apt-get install -y docker-ce
adduser $USER docker
# install docker-compose
sudo curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)"
sudo chmod +x /usr/local/bin/docker-compose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment