Skip to content

Instantly share code, notes, and snippets.

@fabiolimace
Last active April 28, 2025 22:39
Show Gist options
  • Save fabiolimace/da16654d8209c9a221eae244393efd2b to your computer and use it in GitHub Desktop.
Save fabiolimace/da16654d8209c9a221eae244393efd2b to your computer and use it in GitHub Desktop.
Tinyproxy on Docker

Usage

Summary

Steps:

  • Build docker image with docker-build.sh;
  • Run docker container with docker-run.sh;
  • Check the random credentials generated in /home/tinyproxy/tinyproxy.conf.
  • Finally, configure your client proxy settings.

Build and Run

Build image:

sudo ./docker-build.sh

Run container:

sudo ./docker-run.sh

HINT
You may want customize the docker-run.sh script.

Credentials

Check credentials:

sudo docker exec tinyproxy grep BasicAuth /home/tinyproxy/tinyproxy.conf

Client Settings

Client proxy settings to put on ~/.profile:

export http_proxy="http://${AUTHUSER}:${AUTHPASS}@tinyproxy:8888"
export HTTP_PROXY="${http_proxy}"
export https_proxy="${http_proxy}"
export HTTPS_PROXY="${http_proxy}"
export no_proxy="127.0.0.1,localhost"
export NO_PROXY="${no_proxy}"

This is Open Source software released under the MIT license.

#!/bin/bash
#
# Build your image.
#
# docker image rm tinyproxy --force
docker build -t tinyproxy .
#!/bin/bash
#
# Run your container.
#
# Customize this script as you want.
#
# You probably need to run this script just once.
#
# The `--restart=always` option is used to automatically start the container.
#
HOSTPORT=8888
CONTPORT=8888
ALLOWIPS=172.17.0.0/16 # docker default ips
AUTHUSER=$(cat /proc/sys/kernel/random/uuid)
AUTHPASS=$(cat /proc/sys/kernel/random/uuid)
TIMEOUT=600
MAXCLIENTS=100
# docker container rm tinyproxy --force
docker run --restart=always -d -p ${HOSTPORT}:${CONTPORT} \
-e PORT=${CONTPORT} -e ALLOWIPS=${ALLOWIPS} \
-e AUTHUSER=${AUTHUSER} -e AUTHPASS=${AUTHPASS} \
-e TIMEOUT=${TIMEOUT} -e MAXCLIENTS=${MAXCLIENTS} \
--name tinyproxy tinyproxy
FROM ubuntu:24.04
RUN apt update
RUN apt upgrade -y
RUN apt install tinyproxy -y
RUN mkdir --parents /home/tinyproxy
COPY template.conf /home/tinyproxy
COPY entrypoint.sh /home/tinyproxy
WORKDIR /home/tinyproxy
RUN chmod +x ./entrypoint.sh
ENTRYPOINT [ "./entrypoint.sh" ]
#!/bin/bash
: ${PORT:=8888}
: ${ALLOWIPS:=172.17.0.0/16} # docker default ips
: ${AUTHUSER:=$(cat /proc/sys/kernel/random/uuid)}
: ${AUTHPASS:=$(cat /proc/sys/kernel/random/uuid)}
: ${TIMEOUT:=600}
: ${MAXCLIENTS:=100}
ALLOWSTR=$(echo -n "${ALLOWIPS}" | awk 'BEGIN { RS = "," } /^[0-9./]+$/ { print "Allow", $0 }')
cp template.conf tinyproxy.conf
sed -i "s|@PORT|$PORT|" tinyproxy.conf
sed -i "s|@ALLOWSTR|$ALLOWSTR|" tinyproxy.conf
sed -i "s|@AUTHUSER|$AUTHUSER|" tinyproxy.conf
sed -i "s|@AUTHPASS|$AUTHPASS|" tinyproxy.conf
sed -i "s|@TIMEOUT|$TIMEOUT|" tinyproxy.conf
sed -i "s|@MAXCLIENTS|$MAXCLIENTS|" tinyproxy.conf
nohup tinyproxy -c tinyproxy.conf -d > tinyproxy.log
User tinyproxy
Group tinyproxy
Port @PORT
Timeout @TIMEOUT
DefaultErrorFile "/usr/share/tinyproxy/default.html"
StatFile "/usr/share/tinyproxy/stats.html"
LogLevel Info
MaxClients @MAXCLIENTS
Allow 127.0.0.1
Allow ::1
@ALLOWSTR
BasicAuth @AUTHUSER @AUTHPASS
ConnectPort 443
ConnectPort 563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment