Created
May 24, 2017 15:04
-
-
Save thomasv314/441eb79fa1df2217a7eda926bd519c53 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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