Here is a Bash script for installing Dokploy on a Linux server. Make sure you run this as root on a Linux environment that is not a container, and ensure ports 80 and 443 are free.
#!/bin/bash# Ensure the script is run as rootif [ "$(id -u)" != "0" ]; then echo "This script must be run as root" >&2 exit 1fi# Check for Linux OS (not macOS or inside a Docker container)if [ "$(uname)" = "Darwin" ]; then echo "This script must be run on Linux" >&2 exit 1fiif [ -f /.dockerenv ]; then echo "This script must be run on a native Linux host" >&2 exit 1fi# Check for occupied portsif ss -tulnp | grep ':80 ' >/dev/null; then echo "Error: Port 80 is already in use" >&2 exit 1fiif ss -tulnp | grep ':443 ' >/dev/null; then echo "Error: Port 443 is already in use" >&2 exit 1fi# Function to check if a command existscommand_exists() { command -v "$@" > /dev/null 2>&1}# Install Docker if it is not installedif command_exists docker; then echo "Docker already installed"else curl -sSL https://get.docker.com | shfi# Initialize Docker Swarmdocker swarm leave --force 2>/dev/nulladvertise_addr=$(curl -s ifconfig.me)docker swarm init --advertise-addr $advertise_addrecho "Swarm initialized"# Create networkdocker network rm -f dokploy-network 2>/dev/nulldocker network create --driver overlay --attachable dokploy-networkecho "Network created"# Prepare configuration directorymkdir -p /etc/dokploychmod -R 777 /etc/dokploy# Pull and deploy Dokploydocker pull dokploy/dokploy:latestdocker service create \ --name dokploy \ --replicas 1 \ --network dokploy-network \ --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ --mount type=bind,source=/etc/dokploy,target=/etc/dokploy \ --publish published=3000,target=3000,mode=host \ --update-parallelism 1 \ --update-order stop-first \ -e PORT=<Value For PORT eg(3000)> \ -e TRAEFIK_SSL_PORT=<Value For SSL PORT eg(444)> \ -e TRAEFIK_PORT=<VALUE FOR TRAEFIK HTTP PORT eg(81)> \ dokploy/dokploy:latest# Output success messageGREEN="\033[0;32m"YELLOW="\033[1;33m"BLUE="\033[0;34m"NC="\033[0m" # No Colorprintf "${GREEN}Congratulations, Dokploy is installed!${NC}\n"printf "${BLUE}Wait 15 seconds for the server to start${NC}\n"printf "${YELLOW}Please go to http://${advertise_addr}:3000${NC}\n\n"
This script includes checks for common pitfalls, installs Docker if it’s not already installed, initializes a Docker Swarm, creates a network, and then pulls and deploys Dokploy. After the script runs, it provides a success message and instructions for accessing Dokploy.
This structured format clearly lays out the prerequisites, steps, and post-installation information, making it user-friendly and accessible for those performing manual installations.