Docker-Setup: A Tool for Simple Self-Hosted Infrastructure

Docker-Setup: A Tool for Simple Self-Hosted Infrastructure

ยท

4 min read

When setting up a deployment environment, choosing the right tools can feel overwhelming. Many setups become needlessly complex or fail to keep up with current best practices. This guide introduces a streamlined approach using just four essential tools that work together to create a robust self-hosted environment for your applications.

What makes this setup particularly valuable is how it combines simplicity with power - you'll get enterprise-grade features like automatic SSL certificate management and continuous updates, while maintaining an approachable interface that's perfect for both learning and production use.

After completing this setup, your server will gain three key capabilities:

  • First, you'll be able to deploy new applications using docker-compose through Portainer's web interface. This means no more wrestling with command-line complexities - you can manage your entire container infrastructure through a clean, intuitive dashboard.

  • Second, you'll have automatic SSL certificate management through Traefik. Simply add the right labels to your containers, and Traefik handles all the certificate generation and renewal processes behind the scenes.

  • Third, you'll get automated container updates via Watchtower, ensuring your applications stay current with the latest security patches and features without manual intervention.

๐Ÿ’ก

Getting Started

You'll need:

  • A Linux server running any modern distribution

  • Optional: Docker pre-installed (though our tool will handle this for you)

Installation

The entire setup process has been condensed into a single command:

curl -fsSL https://raw.githubusercontent.com/jackkweyunga/docker-setup/main/install.sh | bash

Important Setup Considerations

Network Configuration

If your server's network setup conflicts with Docker's default IP ranges (a common issue in corporate environments), you'll need to adjust the Docker network configuration. Create or modify /etc/docker/daemon.json:

sudo mkdir -p /etc/docker
sudo cd /etc/docker
sudo nano daemon.json

Add these settings, adjusting the IP ranges to match your environment:

{
  "bip": "10.0.1.1/24",
  "default-address-pools": [
    { "base": "10.0.2.0/18", "size": 24 }
  ],
  "log-opts": { "max-size": "100m", "max-file": "5" }
}

The bip setting defines your Docker bridge network's IP range, while default-address-pools configures ranges for user-defined networks. The log settings help prevent your disk from filling up with container logs.

Private Registry Access

If you'll be deploying private containers, authenticate with your registries:

sudo docker login      # For Docker Hub
sudo docker login ghcr.io   # For GitHub Container Registry

For GitHub access, you'll need a token from: github.com/settings/tokens/new

Deploying Your Infrastructure

Start the setup process:

NOTE: Current implementation requires one to run the command twice if docker is not yet installed in the system. this is because after docker installation, one might need to restart the shell for some permissions to take effect.

โ†’ First run

sudo docker-setup

The tool will:

  1. Install Docker if it's not present

โ†’ Second run

sudo docker-setup

The tool will:

  1. Ask for your Portainer domain name ( Enter a dummy domain if not interested )

  2. Request your email for SSL certificates ( Enter a dummy email if not interested )

  3. Deploy the core components

After completion, you'll have three powerful tools at your disposal:

  • Traefik: Your gateway to the outside world, handling routing and SSL

  • Portainer: Your control center for container management

  • Watchtower: Your automated update service

Verify everything is running:

docker ps

Accessing Your New Infrastructure

Visit your Portainer instance at http://:9000 or https:// and set up your admin credentials.

If you encounter a timeout during initial access, a quick restart usually resolves it:

sudo docker restart portainer

Remember: If you're using private registries, configure them in Portainer's settings before attempting deployments.

๐Ÿ’ก
Ready to deploy your first application? Check out our companion guide on deploying dockerized applications in this environment: https://hashnode.com/preview/6752ac7542f77507ad1f985d

This setup strikes an excellent balance between simplicity and capability. It's perfect for those just starting with containerization while being robust enough for production workloads. As you grow more comfortable with these tools, you'll discover even more ways to leverage their features for your specific needs.

ย