Skip to content

Instantly share code, notes, and snippets.

@thisiscetin
Last active October 3, 2016 20:10
Show Gist options
  • Save thisiscetin/f5b28765d79de4bec2ac3b0078074a37 to your computer and use it in GitHub Desktop.
Save thisiscetin/f5b28765d79de4bec2ac3b0078074a37 to your computer and use it in GitHub Desktop.
Prepare VPS for docker / docker-compose | Ubuntu 16.04 minimal server (256mb ram)
#! /bin/bash
# First add a new sudo user to system
# sudo adduser xx sudo
# Second change ssh login to key only
# https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2
# And then run this file
# Add 1G swapfile as root
sudo -i
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
echo "vm.vfs_cache_pressure = 50" >> /etc/sysctl.conf
exit
# setup ufw firewall
sudo ufw default deny incoming && ufw default allow outgoing
sudo ufw allow ssh && ufw allow 80/tcp && ufw allow 443/tcp
sudo nano /etc/default/ufw
# Change:
# DEFAULT_FORWARD_POLICY="DROP"
# to
# DEFAULT_FORWARD_POLICY="ACCEPT"
sudo ufw enable
# install docker
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update && apt-cache policy docker-engine
sudo apt-get install -y docker-engine
sudo usermod -aG docker $(whoami)
# install docker-compose
sudo apt-get -y install python-pip && pip install docker-compose
# reboot the system
@thisiscetin
Copy link
Author

thisiscetin commented Oct 1, 2016

You should include docker exception to firewall if your container is accessible through port forwarding.

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