Skip to content

Instantly share code, notes, and snippets.

@AlcibiadesCleinias
Last active February 15, 2023 14:46
Show Gist options
  • Save AlcibiadesCleinias/34782bab9ece1a074af2636962f7fbe2 to your computer and use it in GitHub Desktop.
Save AlcibiadesCleinias/34782bab9ece1a074af2636962f7fbe2 to your computer and use it in GitHub Desktop.
#!/bin/bash
#####################
# Portainer Install #
#####################
# # Flow
# 1. Copy the file into portainer.sh that you may create via `vim` + `i` + `cntr+v` + `esc` + `!` + `wq` + `enter`
# 2. `chmod +x portainer.sh`
# 3. `./portainer.sh`
# 4. Go to localhost:9000 and generate credentials.
# Hot to destroy in 1 command:
# $docker stop portainer && docker rm portainer && docker volume rm portainer_data
usage() { echo "Usage: $0 [-p <8000|9000>] [-s <8000|9000>]" 1>&2; exit 1; }
# Defaults:
port=9000
sshport=8000
# Parsing
while getopts p:s:h flag
do
# shellcheck disable=SC2220
case "${flag}" in
p) port=${OPTARG};;
s) sshport=${OPTARG};; # Port 8000 is a SSH tunnel server and is used to create a secure tunnel between the agent and the Portainer instance.
h | [?]) usage ; exit;;
esac
done
shift $((OPTIND-1))
# Main
container_name=portainer
container_image_name=portainer/portainer
container_volume_name=portainer_data
if [ ! "$(docker ps | grep $container_name)" ]; then
echo "Container $container_name is not running"
echo "Create volume $container_volume_name ..."
docker volume create $container_volume_name
echo "Run $container_name based on $container_image_name image ..."
echo "GUI port: $port"
echo "SSH port: $sshport"
docker run -d -p $port:9000 -p $sshport:8000 --name $container_name --restart always -v /var/run/docker.sock:/var/run/docker.sock -v $container_volume_name:/data $container_image_name
else
echo "$container_name have been running already, nothing to install and start"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment