Auto-Start Harbor on Boot: Systemd Setup for Docker Compose Deployments
The article explains why Harbor containers fail to start automatically after a server reboot, demonstrates the failure with a reboot test, and provides a complete systemd-based solution including Docker service enablement, custom start/stop scripts, and a systemd unit file to ensure Harbor services launch on boot.
Why Harbor Needs Manual Startup
Harbor is deployed via Docker Compose, and Docker containers do not automatically start on boot unless configured with a restart policy. After a server reboot:
Docker service may start automatically (if enabled), but Harbor containers remain stopped.
If Docker itself is not enabled, the entire Docker environment and Harbor stay down.
Container dependency chains break: Harbor services use depends_on relationships; if a dependency fails to start, dependent services repeatedly restart and ultimately fail.
The core solution: ensure Docker starts on boot, then make Harbor containers follow.
Simulated Reboot Scenario
Normal running state shows all Harbor containers healthy.
Reboot command: reboot After reboot, some services fail to start, requiring manual intervention. Exception services include:
harbor-jobservice nginx registryctl harbor-portalSolution: Manage Harbor with systemd
Using systemd integrates Harbor into the system startup flow, enabling auto-start, status checks, and log tracking.
Steps (CentOS Example)
Ensure Docker service is enabled on boot
# Check Docker status
systemctl status docker
# Enable auto-start if not already
systemctl enable docker --nowCreate Harbor start/stop scripts
Assuming Harbor is installed at /data/harbor:
# Start script start.sh
cat > /data/harbor/start.sh << 'EOF'
#!/bin/bash
cd /data/harbor
docker-compose up -d
EOF
# Stop script stop.sh
cat > /data/harbor/stop.sh << 'EOF'
#!/bin/bash
cd /data/harbor
docker-compose down
EOF
# Make scripts executable
chmod +x /data/harbor/start.sh /data/harbor/stop.shCreate systemd service file
Create /etc/systemd/system/harbor.service:
cat > /etc/systemd/system/harbor.service << 'EOF'
[Unit]
Description=Harbor Image Registry
# Ensure Docker starts before Harbor
After=docker.service
# Require Docker service; if Docker fails, Harbor won't start
Requires=docker.service
[Service]
# One-shot script execution
Type=oneshot
# Start command
ExecStart=/data/harbor/start.sh
# Stop command
ExecStop=/data/harbor/stop.sh
# Keep service shown as running after script exits
RemainAfterExit=yes
[Install]
# Activate in multi-user mode
WantedBy=multi-user.target
EOFEnable and verify
# Reload systemd configuration
systemctl daemon-reload
# Avoid SELinux blocking script execution
# Temporarily disable SELinux (current session)
setenforce 0
# Permanently disable SELinux
sed -i 's/enforcing/disabled/' /etc/selinux/config
# Enable Harbor auto-start
systemctl enable harbor.service
# Manual start test
systemctl start harbor.service
# Check status (should show active (exited))
systemctl status harbor.serviceVerification
Reboot the server and run docker ps. If Harbor containers (e.g., harbor-core, registry, postgresql) are running, the configuration succeeds.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Cilantro Loves Linux
Focused on Linux system operations and maintenance technology exchange, regularly publishing in-depth technical articles covering core areas such as system architecture, performance optimization, and security hardening. Whether you are a beginner or a seasoned expert, you can find valuable resources to enhance your skills and solve problems here. Follow us to explore the mysteries of Linux operations!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
