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/null get_ip() { # Try to get IPv4 local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null) if [ -n "$ipv4" ]; then echo "$ipv4" else # Try to get IPv6 local ipv6=$(curl -6s https://ifconfig.io 2>/dev/null) if [ -n "$ipv6" ]; then echo "$ipv6" fi fi } advertise_addr="${ADVERTISE_ADDR:-$(get_ip)}" docker swarm init --advertise-addr $advertise_addr if [ $? -ne 0 ]; then echo "Error: Failed to initialize Docker Swarm" >&2 exit 1 fi docker network rm -f dokploy-network 2>/dev/null docker network create --driver overlay --attachable dokploy-network echo "Network created" mkdir -p /etc/dokploy chmod 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)> \ -e ADVERTISE_ADDR=$advertise_addr \ 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.
The --advertise-addr parameter in the docker swarm init command specifies the IP address or interface that the Docker Swarm manager node should advertise to other nodes in the Swarm. This address is used by other nodes to communicate with the manager.
By default, this script uses the external IP address of the server, obtained using the curl -s ifconfig.me command. However, you might need to customize this address based on your network configuration, especially if your server has multiple network interfaces or if you're setting up Swarm in a private network.
To customize the --advertise-addr parameter, replace the line: advertise_addr=$(curl -s ifconfig.me) with your desired IP address or interface, for example:
advertise_addr="192.168.1.100"
:warning: This IP address should be accessible to all nodes that will join the Swarm.