docker-shadowsocks

by yangqi
7 deployments · 5 still active · last rev. 24 days ago

Install shadowsocks server in a minimal docker container (only 14.3 MB)

Compatible with: Arch Linux, CentOS 7, Debian 8, Debian 9, Ubuntu 16.04 LTS, Ubuntu 18.04 LTS, Ubuntu 18.10, CentOS 6.8, Ubuntu 14.04 LTS
						#!/bin/sh

# <UDF name="PORT" Label="Server port" default="8388" example="Enter port number here." />
# <UDF name="METHOD" Label="Encryption method" oneOf="chacha20,salsa20,chacha20-ietf,aes-256-cfb,aes-192-cfb,aes-128-cfb" default="aes-256-cfb" example="Enter something here." />
# <UDF name="PASSWORD" Label="Password" default="" example="Enter password here." />
# <UDF name="TIMEOUT" Label="Timeout" default="300" example="Enter timeout seconds here." />
# <UDF name="DNS" Label="DNS Servers" default="8.8.8.8,8.8.4.4" example="Enter DNS servers here, separated by comma." />

set -e

# Save stdout and stderr
exec 6>&1
exec 5>&2

# Redirect stdout and stderr to a file
exec > /root/StackScript.out
exec 2>&1

create_docker_compose() {
    mkdir ~/shadowsocks
    cat > ~/shadowsocks/docker-ss.yml <<HEREDOC
shadowsocks:
  image: shadowsocks/shadowsocks-libev
  ports:
    - "$PORT:$PORT/tcp"
    - "$PORT:$PORT/udp"
  environment:
    - METHOD=$METHOD
    - PASSWORD=$PASSWORD
    - SERVER_PORT=$PORT
    - TIMEOUT=$TIMEOUT
    - DNS_ADDRS=$DNS
  restart: always
HEREDOC
}

# This sets the variable $IPADDR to the IP address the new Linode receives.
IPADDR=$(/sbin/ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://')

lsb_dist=""
# Every system that we officially support has /etc/os-release
if [ -r /etc/os-release ]; then
    lsb_dist="$(. /etc/os-release && echo "$ID")"
fi

case "$lsb_dist" in

    ubuntu|debian)
        apt-get update
        apt-get -y upgrade
        curl -fsSL https://get.docker.com -o get-docker.sh
        sh get-docker.sh
        apt-get -y install docker-compose
        create_docker_compose
        docker-compose -f ~/shadowsocks/docker-ss.yml up -d
    ;;

    centos)
        yum -y update
        curl -fsSL https://get.docker.com -o get-docker.sh
        sh get-docker.sh
        apt-get -y install docker-compose
        create_docker_compose
        docker-compose -f ~/shadowsocks/docker-ss.yml up -d
    ;;

    arch)
        pacman -Syu
        pacman -S docker docker-compose
        create_docker_compose
        docker-compose -f ~/shadowsocks/docker-ss.yml up -d
    ;;

    *)
        echo "Your distribution is not supported by this StackScript"
        exit
    ;;

esac