Skip to content

Instantly share code, notes, and snippets.

@thomasv314
Created May 24, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasv314/441eb79fa1df2217a7eda926bd519c53 to your computer and use it in GitHub Desktop.
Save thomasv314/441eb79fa1df2217a7eda926bd519c53 to your computer and use it in GitHub Desktop.
#!/bin/bash
SQUID_DOCKER_IMAGE="sameersbn/squid"
SQUID_DOCKER_VERSION="3.3.8-23"
SQUID_DOCKER_FQN="$SQUID_DOCKER_IMAGE:$SQUID_DOCKER_VERSION"
CONTAINER_NAME="squid"
function pull_image_if_missing() {
docker inspect $SQUID_DOCKER_FQN &> /dev/null
image_exists=$?
if [ "$image_exists" -eq 0 ]; then
echo "Docker image already exists."
else
echo "Could not find docker image."
docker pull $SQUID_DOCKER_IMAGE:$SQUID_DOCKER_VERSION
echo "Pulled docker image $SQUID_DOCKER_IMAGE:$SQUID_DOCKER_VERSION"
fi
}
function start_container_unless_running() {
docker ps -f name=$CONTAINER_NAME | grep $CONTAINER_NAME &> /dev/null
is_running=$?
if [ "$is_running" -eq 0 ]; then
echo "Squid container is already running."
else
echo "Starting squid container.."
docker run --name $CONTAINER_NAME \
-d \
--restart=always \
--publish 3128:3128 \
$SQUID_DOCKER_IMAGE:$SQUID_DOCKER_VERSION
sleep 5 # sleep 5 seconds to let it start before we tail
fi
}
function tail_logs() {
echo "Tailing logs.. be sure to set:"
echo ""
echo " export http_proxy=http://localhost:3128"
echo " export https_proxy=http://localhost:3128"
echo " export HTTP_PROXY=http://localhost:3128"
echo " export HTTPS_PROXY=http://localhost:3128"
echo ""
docker exec -it $CONTAINER_NAME tail -f /var/log/squid3/access.log
}
pull_image_if_missing && start_container_unless_running && tail_logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment