#!/bin/bash ### ### Context of this script can be found in the following reddit thread ### https://www.reddit.com/r/ServerAvatar/comments/uco5cg/how_to_run_selfhosted_docker_instance_of_n8n_on_a/ ### # Get the container image ID for the current instance cid=$(docker ps -a -q --filter ancestor=n8nio/n8n) # If $cid is empty then there doesn't exist # a prior instance to stop and remove, and # therefore we can skip these operations... if [ ! -z "$cid" ] then echo "Container Instance ID: $cid" echo "Stopping Instance..." docker stop $cid echo "Removing Instance..." docker rm $cid fi # ... and proceed directly to pulling the latest version of n8n echo "Pulling Latest Image..." docker pull n8nio/n8n echo "Launching New Instance..." docker run -d --restart=always --name n8n -p 5678:5678 \ --env-file /home/n8n.io/n8nio/.env \ -v /home/n8n.io/n8nio/.n8n:/home/node/.n8n n8nio/n8n