├── .github └── FUNDING.yml ├── Dockerfile ├── scripts ├── start.sh └── start-server.sh ├── README.md └── tailscale.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ich777 -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ich777/debian-baseimage:bullseye_amd64 2 | 3 | LABEL org.opencontainers.image.authors="admin@minenet.at" 4 | LABEL org.opencontainers.image.source="https://github.com/ich777/docker-steamcmd-server" 5 | 6 | RUN apt-get update && \ 7 | apt-get -y install --no-install-recommends lib32gcc-s1 lib32stdc++6 lib32z1 && \ 8 | rm -rf /var/lib/apt/lists/* 9 | 10 | ENV DATA_DIR="/serverdata" 11 | ENV STEAMCMD_DIR="${DATA_DIR}/steamcmd" 12 | ENV SERVER_DIR="${DATA_DIR}/serverfiles" 13 | ENV GAME_ID="template" 14 | ENV GAME_NAME="template" 15 | ENV GAME_PARAMS="template" 16 | ENV GAME_PORT=27015 17 | ENV VALIDATE="" 18 | ENV UMASK=000 19 | ENV UID=99 20 | ENV GID=100 21 | ENV USERNAME="" 22 | ENV PASSWRD="" 23 | ENV USER="steam" 24 | ENV DATA_PERM=770 25 | 26 | RUN mkdir $DATA_DIR && \ 27 | mkdir $STEAMCMD_DIR && \ 28 | mkdir $SERVER_DIR && \ 29 | useradd -d $DATA_DIR -s /bin/bash $USER && \ 30 | chown -R $USER $DATA_DIR && \ 31 | ulimit -n 2048 32 | 33 | ADD /scripts/ /opt/scripts/ 34 | RUN chmod -R 770 /opt/scripts/ 35 | 36 | #Server Start 37 | ENTRYPOINT ["/opt/scripts/start.sh"] 38 | -------------------------------------------------------------------------------- /scripts/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "---Ensuring UID: ${UID} matches user---" 3 | usermod -u ${UID} ${USER} 4 | echo "---Ensuring GID: ${GID} matches user---" 5 | groupmod -g ${GID} ${USER} > /dev/null 2>&1 ||: 6 | usermod -g ${GID} ${USER} 7 | echo "---Setting umask to ${UMASK}---" 8 | umask ${UMASK} 9 | 10 | echo "---Checking for optional scripts---" 11 | cp -f /opt/custom/user.sh /opt/scripts/start-user.sh > /dev/null 2>&1 ||: 12 | cp -f /opt/scripts/user.sh /opt/scripts/start-user.sh > /dev/null 2>&1 ||: 13 | 14 | if [ -f /opt/scripts/start-user.sh ]; then 15 | echo "---Found optional script, executing---" 16 | chmod -f +x /opt/scripts/start-user.sh ||: 17 | /opt/scripts/start-user.sh || echo "---Optional Script has thrown an Error---" 18 | else 19 | echo "---No optional script found, continuing---" 20 | fi 21 | 22 | echo "---Taking ownership of data...---" 23 | chown -R root:${GID} /opt/scripts 24 | chmod -R 750 /opt/scripts 25 | chown -R ${UID}:${GID} ${DATA_DIR} 26 | 27 | # Fix for CSDM not working properly 28 | if [ -f "${SERVER_DIR}/cstrike/addons/sourcemod/gamedata/cssdm.games.txt" ]; then 29 | chmod 550 ${SERVER_DIR}/cstrike/addons/sourcemod/gamedata/cssdm.games.txt 30 | fi 31 | 32 | echo "---Starting...---" 33 | term_handler() { 34 | kill -SIGTERM "$killpid" 35 | wait "$killpid" -f 2>/dev/null 36 | exit 143; 37 | } 38 | 39 | trap 'kill ${!}; term_handler' SIGTERM 40 | su ${USER} -c "/opt/scripts/start-server.sh" & 41 | killpid="$!" 42 | while true 43 | do 44 | wait $killpid 45 | exit 0; 46 | done 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SteamCMD in Docker optimized for Unraid 2 | This Docker will download and install SteamCMD and the according game that is pulled via specifying the Tag. 3 | 4 | **Please see the different Tags/Branches which games are available.** 5 | 6 | ## Example Env params for CS:Source 7 | | Name | Value | Example | 8 | | --- | --- | --- | 9 | | STEAMCMD_DIR | Folder for SteamCMD | /serverdata/steamcmd | 10 | | SERVER_DIR | Folder for gamefile | /serverdata/serverfiles | 11 | | GAME_ID | The GAME_ID that the container downloads at startup. If you want to install a static or beta version of the game change the value to: '232330 -beta YOURBRANCH' (without quotes, replace YOURBRANCH with the branch or version you want to install). | 232330 | 12 | | GAME_NAME | SRCDS gamename | cstrike | 13 | | GAME_PARAMS | Values to start the server | -secure +maxplayers 32 +map de_dust2 | 14 | | UID | User Identifier | 99 | 15 | | GID | Group Identifier | 100 | 16 | | GAME_PORT | Port the server will be running on | 27015 | 17 | | VALIDATE | Validates the game data | blank | 18 | | USERNAME | Leave blank for anonymous login | blank | 19 | | PASSWRD | Leave blank for anonymous login | blank | 20 | 21 | ## Run example for CS:Source 22 | ``` 23 | docker run --name CSSource -d \ 24 | -p 27015:27015 -p 27015:27015/udp \ 25 | --env 'GAME_ID=232330' \ 26 | --env 'GAME_NAME=cstrike' \ 27 | --env 'GAME_PORT=27015' \ 28 | --env 'GAME_PARAMS=-secure +maxplayers 32 +map de_dust2' \ 29 | --env 'UID=99' \ 30 | --env 'GID=100' \ 31 | --volume /path/to/steamcmd:/serverdata/steamcmd \ 32 | --volume /path/to/cstrikesource:/serverdata/serverfiles \ 33 | ich777/steamcmd:latest 34 | ``` 35 | 36 | This Docker was mainly edited for better use with Unraid, if you don't use Unraid you should definitely try it! 37 | 38 | This Docker is forked from mattieserver, thank you for this wonderfull Docker. 39 | 40 | #### Support Thread: https://forums.unraid.net/topic/79530-support-ich777-gameserver-dockers/ -------------------------------------------------------------------------------- /scripts/start-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ ! -f ${STEAMCMD_DIR}/steamcmd.sh ]; then 3 | echo "SteamCMD not found!" 4 | wget -q -O ${STEAMCMD_DIR}/steamcmd_linux.tar.gz http://media.steampowered.com/client/steamcmd_linux.tar.gz 5 | tar --directory ${STEAMCMD_DIR} -xvzf /serverdata/steamcmd/steamcmd_linux.tar.gz 6 | rm ${STEAMCMD_DIR}/steamcmd_linux.tar.gz 7 | fi 8 | 9 | echo "---Update SteamCMD---" 10 | if [ "${USERNAME}" == "" ]; then 11 | ${STEAMCMD_DIR}/steamcmd.sh \ 12 | +login anonymous \ 13 | +quit 14 | else 15 | ${STEAMCMD_DIR}/steamcmd.sh \ 16 | +login ${USERNAME} ${PASSWRD} \ 17 | +quit 18 | fi 19 | 20 | echo "---Update Server---" 21 | if [ "${USERNAME}" == "" ]; then 22 | if [ "${VALIDATE}" == "true" ]; then 23 | echo "---Validating installation---" 24 | ${STEAMCMD_DIR}/steamcmd.sh \ 25 | +force_install_dir ${SERVER_DIR} \ 26 | +login anonymous \ 27 | +app_update ${GAME_ID} validate \ 28 | +quit 29 | else 30 | ${STEAMCMD_DIR}/steamcmd.sh \ 31 | +force_install_dir ${SERVER_DIR} \ 32 | +login anonymous \ 33 | +app_update ${GAME_ID} \ 34 | +quit 35 | fi 36 | else 37 | if [ "${VALIDATE}" == "true" ]; then 38 | echo "---Validating installation---" 39 | ${STEAMCMD_DIR}/steamcmd.sh \ 40 | +force_install_dir ${SERVER_DIR} \ 41 | +login ${USERNAME} ${PASSWRD} \ 42 | +app_update ${GAME_ID} validate \ 43 | +quit 44 | else 45 | ${STEAMCMD_DIR}/steamcmd.sh \ 46 | +force_install_dir ${SERVER_DIR} \ 47 | +login ${USERNAME} ${PASSWRD} \ 48 | +app_update ${GAME_ID} \ 49 | +quit 50 | fi 51 | fi 52 | 53 | echo "---Prepare Server---" 54 | if [ ! -f ${DATA_DIR}/.steam/sdk32/steamclient.so ]; then 55 | if [ ! -d ${DATA_DIR}/.steam ]; then 56 | mkdir ${DATA_DIR}/.steam 57 | fi 58 | if [ ! -d ${DATA_DIR}/.steam/sdk32 ]; then 59 | mkdir ${DATA_DIR}/.steam/sdk32 60 | fi 61 | cp -R ${STEAMCMD_DIR}/linux32/* ${DATA_DIR}/.steam/sdk32/ 62 | fi 63 | chmod -R ${DATA_PERM} ${DATA_DIR} 64 | echo "---Server ready---" 65 | 66 | echo "---Start Server---" 67 | cd ${SERVER_DIR} 68 | ${SERVER_DIR}/srcds_run -game ${GAME_NAME} ${GAME_PARAMS} -console +port ${GAME_PORT} -------------------------------------------------------------------------------- /tailscale.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # The script will then add the container to your Tailscale network. 3 | # 4 | # For more information see: [Link TBD] 5 | 6 | error_handler() { 7 | echo 8 | echo "=======================" 9 | exit 1 10 | } 11 | 12 | echo "=======================" 13 | echo 14 | 15 | # Import variables from s6-overlay images 16 | if [ -x "/usr/bin/with-contenv" ]; then 17 | echo "just-containers s6-overlay image found, importing variables..." 18 | ENV_VARS="$(/usr/bin/with-contenv bash -c 'env')" 19 | 20 | while IFS='=' read -r KEY VALUE; do 21 | export "${KEY}"="${VALUE}" 22 | done <<< "${ENV_VARS}" 23 | fi 24 | 25 | if [[ ! -f /usr/bin/tailscale || ! -f /usr/bin/tailscaled ]]; then 26 | if [ ! -z "${TAILSCALE_EXIT_NODE_IP}" ]; then 27 | if [ ! -c /dev/net/tun ]; then 28 | echo "ERROR: Device /dev/net/tun not found!" 29 | echo " Make sure to pass through /dev/net/tun to the container." 30 | error_handler 31 | fi 32 | APT_IPTABLES="iptables " 33 | fi 34 | 35 | echo "Detecting Package Manager..." 36 | if which apt-get >/dev/null 2>&1; then 37 | echo "Detected Advanced Package Tool!" 38 | PACKAGES_UPDATE="apt-get update" 39 | PACKAGES_INSTALL="apt-get -y install --no-install-recommends" 40 | elif which apk >/dev/null 2>&1; then 41 | echo "Detected Alpine Package Keeper!" 42 | PACKAGES_UPDATE="apk update" 43 | PACKAGES_INSTALL="apk add" 44 | else 45 | echo "ERROR: Detection failed!" 46 | error_handler 47 | fi 48 | 49 | echo "Installing dependencies..." 50 | echo "Please wait..." 51 | ${PACKAGES_UPDATE} >/dev/null 2>&1 52 | ${PACKAGES_INSTALL} jq wget ca-certificates ${APT_IPTABLES}>/dev/null 2>&1 53 | echo "Done" 54 | 55 | if [ "${APT_IPTABLES}" == "iptables " ]; then 56 | if ! iptables -L >/dev/null 2>&1; then 57 | echo "ERROR: Cap: NET_ADMIN not available!" 58 | echo " Make sure to add --cap-add=NET_ADMIN to the Extra Parameters" 59 | error_handler 60 | fi 61 | fi 62 | 63 | echo "Tailscale not found, downloading..." 64 | echo "Please wait..." 65 | 66 | TAILSCALE_JSON=$(wget -qO- 'https://pkgs.tailscale.com/stable/?mode=json') 67 | 68 | if [ -z "${TAILSCALE_JSON}" ]; then 69 | echo "ERROR: Can't get Tailscale JSON" 70 | error_handler 71 | fi 72 | 73 | TAILSCALE_TARBALL=$(echo "${TAILSCALE_JSON}" | jq -r .Tarballs.amd64) 74 | TAILSCALE_VERSION=$(echo "${TAILSCALE_JSON}" | jq -r .TarballsVersion) 75 | 76 | if [ ! -d /tmp/tailscale ]; then 77 | mkdir -p /tmp/tailscale 78 | fi 79 | 80 | if wget -q -nc --show-progress --progress=bar:force:noscroll -O /tmp/tailscale/tailscale.tgz "https://pkgs.tailscale.com/stable/${TAILSCALE_TARBALL}" ; then 81 | echo "Download from Tailscale version ${TAILSCALE_VERSION} successful!" 82 | else 83 | echo "ERROR: Download from Tailscale version ${TAILSCALE_VERSION} failed!" 84 | rm -rf /tmp/tailscale 85 | error_handler 86 | fi 87 | 88 | cd /tmp/tailscale 89 | tar -xf /tmp/tailscale/tailscale.tgz 90 | cp /tmp/tailscale/tailscale_${TAILSCALE_VERSION}_amd64/tailscale /usr/bin/tailscale 91 | cp /tmp/tailscale/tailscale_${TAILSCALE_VERSION}_amd64/tailscaled /usr/bin/tailscaled 92 | rm -rf /tmp/tailscale 93 | 94 | echo "Done" 95 | 96 | else 97 | echo "Tailscale found, continuing..." 98 | fi 99 | 100 | unset TSD_PARAMS 101 | unset TS_PARAMS 102 | 103 | if [ ! -z "${TAILSCALE_STATE_DIR}" ]; then 104 | TSD_STATE_DIR="${TAILSCALE_STATE_DIR}" 105 | elif [ -v SERVER_DIR ]; then 106 | TSD_STATE_DIR=${SERVER_DIR}/.tailscale_state 107 | echo "Settings Tailscale state dir to: ${TSD_STATE_DIR}" 108 | elif [ -v DATA_DIR ]; then 109 | TSD_STATE_DIR=${DATA_DIR}/.tailscale_state 110 | echo "Settings Tailscale state dir to: ${TSD_STATE_DIR}" 111 | else 112 | if [ -z "${TAILSCALE_STATE_DIR}" ]; then 113 | TAILSCALE_STATE_DIR="/config/.tailscale_state" 114 | fi 115 | TSD_STATE_DIR=${TAILSCALE_STATE_DIR} 116 | echo "Settings Tailscale state dir to: ${TSD_STATE_DIR}" 117 | fi 118 | 119 | if [ ! -d ${TS_STATE_DIR} ]; then 120 | mkdir -p ${TS_STATE_DIR} 121 | fi 122 | 123 | if [ ! -z "${TAILSCALE_EXIT_NODE_IP}" ]; then 124 | echo "Using ${TAILSCALE_EXIT_NODE_IP} as Exit Node! See https://tailscale.com/kb/1103/exit-nodes" 125 | TS_PARAMS=" --exit-node=${TAILSCALE_EXIT_NODE_IP}" 126 | if [ ! -z "${TAILSCALE_ALLOW_LAN_ACCESS}" ]; then 127 | echo "Enabling local LAN Access to the container!" 128 | TS_PARAMS+=" --exit-node-allow-lan-access" 129 | fi 130 | else 131 | if [ -z "${TAILSCALE_USERSPACE_NETWORKING}" ] || [ "${TAILSCALE_USERSPACE_NETWORKING}" == "true" ]; then 132 | TSD_PARAMS+="-tun=userspace-networking " 133 | else 134 | if [ ! -c /dev/net/tun ]; then 135 | echo "ERROR: Device /dev/net/tun not found!" 136 | echo " Make sure to pass through /dev/net/tun to the container and add the" 137 | echo " parameter --cap-add=NET_ADMIN to the Extra Parameters!" 138 | error_handler 139 | fi 140 | fi 141 | fi 142 | 143 | if [ "${TAILSCALE_USE_SSH}" == "true" ]; then 144 | echo "Enabling SSH. See https://tailscale.com/kb/1193/tailscale-ssh" 145 | TS_PARAMS+=" --ssh" 146 | fi 147 | 148 | if [ "${TAILSCALE_LOG}" != "false" ]; then 149 | TSD_PARAMS+=">>/var/log/tailscaled 2>&1 " 150 | TSD_MSG=" with log file /var/log/tailscaled" 151 | else 152 | TSD_PARAMS+=">/dev/null 2>&1 " 153 | fi 154 | 155 | if [[ ! -z "${TAILSCALE_AUTHKEY}" && -f ${TSD_STATE_DIR}/.initialized ]]; then 156 | echo 157 | echo "-> It is now save to remove the variable TAILSCALE_AUTHKEY from your template <-" 158 | echo 159 | unset TAILSCALE_AUTHKEY 160 | fi 161 | 162 | if [ ! -z "${TAILSCALE_AUTHKEY}" ]; then 163 | TS_AUTH="--authkey=${TAILSCALE_AUTHKEY} " 164 | fi 165 | 166 | if [ ! -z "${TAILSCALE_HOSTNAME}" ]; then 167 | echo "Setting host name to ${TAILSCALE_HOSTNAME}" 168 | TS_PARAMS+=" --hostname=${TAILSCALE_HOSTNAME/ /}" 169 | fi 170 | 171 | if [ "${TAILSCALE_EXIT_NODE}" == "true" ]; then 172 | echo "Configuring container as Exit Node! See https://tailscale.com/kb/1103/exit-nodes" 173 | TS_PARAMS+=" --advertise-exit-node" 174 | fi 175 | 176 | if [ ! -z "${TAILSCALED_PARAMS}" ]; then 177 | TSD_PARAMS="${TAILSCALED_PARAMS} ${TSD_PARAMS}" 178 | fi 179 | 180 | if [ ! -z "${TAILSCALE_PARAMS}" ]; then 181 | TS_PARAMS="${TAILSCALE_PARAMS}${TS_PARAMS}" 182 | fi 183 | 184 | echo "Starting tailscaled${TSD_MSG}" 185 | eval tailscaled -statedir=${TSD_STATE_DIR} ${TSD_PARAMS}& 186 | 187 | echo "Starting tailscale" 188 | eval tailscale up ${TS_AUTH}${TS_PARAMS} 189 | EXIT_STATUS="$?" 190 | 191 | if [ "${EXIT_STATUS}" == "0" ]; then 192 | echo "Connecting to Tailscale successful!" 193 | if [ ! -f ${TSD_STATE_DIR}/.initialized ]; then 194 | echo "Please don't remove this file!" > ${TSD_STATE_DIR}/.initialized 195 | fi 196 | else 197 | echo "ERROR: Connecting to Tailscale not successful!" 198 | if [ -f /var/log/tailscaled ]; then 199 | echo "Please check the logs:" 200 | tail -20 /var/log/tailscaled 201 | echo "=======================" 202 | fi 203 | error_handler 204 | fi 205 | 206 | if [[ ! -z "${TAILSCALE_SERVE_PORT}" && "$(tailscale status --json | jq -r '.CurrentTailnet.MagicDNSEnabled')" == "false" ]] ; then 207 | echo "ERROR: Enable HTTPS on your Tailscale account to use Tailscale Serve/Funnel." 208 | echo "See: https://tailscale.com/kb/1153/enabling-https" 209 | error_handler 210 | fi 211 | 212 | if [ ! -z ${TAILSCALE_SERVE_PORT} ]; then 213 | if [ ! -z "${TAILSCALE_SERVE_PATH}" ]; then 214 | TAILSCALE_SERVE_PATH="=${TAILSCALE_SERVE_PATH}" 215 | fi 216 | if [ -z "${TAILSCALE_SERVE_MODE}" ]; then 217 | TAILSCALE_SERVE_MODE="https" 218 | fi 219 | if [ -z "${TAILSCALE_SERVE_PROTOCOL_PORT}" ]; then 220 | TAILSCALE_SERVE_PROTOCOL_PORT="=443" 221 | fi 222 | if [ "${TAILSCALE_FUNNEL}" == "true" ]; then 223 | echo "Enabling Funnel! See https://tailscale.com/kb/1223/funnel" 224 | eval tailscale funnel --bg --"${TAILSCALE_SERVE_MODE}"${TAILSCALE_SERVE_PROTOCOL_PORT}${TAILSCALE_SERVE_PATH} http://localhost:"${TAILSCALE_SERVE_PORT}${TAILSCALE_SERVER_LOCALPATH}" 225 | else 226 | echo "Enabling Serve! See https://tailscale.com/kb/1312/serve" 227 | eval tailscale serve --bg --"${TAILSCALE_SERVE_MODE}"${TAILSCALE_SERVE_PROTOCOL_PORT}${TAILSCALE_SERVE_PATH} http://localhost:"${TAILSCALE_SERVE_PORT}${TAILSCALE_SERVER_LOCALPATH}" 228 | fi 229 | fi 230 | 231 | echo 232 | echo "=======================" --------------------------------------------------------------------------------