Skip to content

Instantly share code, notes, and snippets.

@satrapu
Last active August 24, 2017 07:52
Show Gist options
  • Save satrapu/0185087063ffb1892a051a8566b6f3ee to your computer and use it in GitHub Desktop.
Save satrapu/0185087063ffb1892a051a8566b6f3ee to your computer and use it in GitHub Desktop.
Oh, my ZSH! Portainer alias for Linux
# This alias is used for replacing the current Portainer Docker container with a given version.
# This is a fragment from your custom configuration file you have specified when you setup Oh, my ZSH! on your machine.
#
# The alias works on Ubuntu 16.04, but it should also work on other Linux distributions as well.
# It doesn't work on MacOS, since the provided xargs tool doesn't have the --no-run-if-empty option; you'll need to
# modify it to have it work on this OS too.
#
# Oh, my ZSH! can be found here: http://ohmyz.sh/.
# Portainer, "the easiest way to manage Docker", can be found here: https://portainer.io/.
#----------------------
TOOLS_HOME=<PATH_TO_YOUR_FOLDER_WHERE_YOU_KEEP_YOUR_TOOLS>
PORTAINER_VERSION='1.14.0'
PORTAINER_DOCKER_IMAGE_NAME='portainer/portainer'
PORTAINER_DOCKER_IMAGE_TAG="${PORTAINER_VERSION:-latest}"
PORTAINER_CONTAINER_NAME='portainer'
PORTAINER_HOST_PORT='9000'
PORTAINER_VOLUME_HOME="$TOOLS_HOME/portainer/data"
alias pc="echo 'Replacing old Portainer instance with a newer one ...' \
&& sudo docker container ls --quiet --filter name=$PORTAINER_CONTAINER_NAME \
| xargs --no-run-if-empty -I xargs_containerId \
sh -c \"echo 'Stoping container with id xargs_containerId ... ';\
sudo docker container stop xargs_containerId; \
echo 'Removing container with id xargs_containerId ...'; \
sudo docker container rm --force xargs_containerId\" \
&& sudo docker image ls --quiet --filter reference=$PORTAINER_DOCKER_IMAGE_NAME \
| xargs --no-run-if-empty -I xargs_imageId \
sh -c \"echo 'Removing image with id xargs_imageId ...';\
sudo docker image rm --force xargs_imageId\" \
&& sudo docker container run \
--name $PORTAINER_CONTAINER_NAME \
--detach \
--publish $PORTAINER_HOST_PORT:9000 \
--restart=unless-stopped \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume $PORTAINER_VOLUME_HOME:/data \
$PORTAINER_DOCKER_IMAGE_NAME:$PORTAINER_DOCKER_IMAGE_TAG \
&& echo 'Portainer with tag $PORTAINER_DOCKER_IMAGE_TAG is available at http://localhost:$PORTAINER_HOST_PORT' \
&& sensible-browser http://localhost:$PORTAINER_HOST_PORT"
alias portainer='pc'
#----------------------
# When you want to start Portainer on your machine, just run one of the below commands into your Oh, my ZSH! terminal:
# pc
# portainer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment