User Tools

Site Tools


creating_docker-compose_applications

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
creating_docker-compose_applications [2026/10/03 17:02] – admincreating_docker-compose_applications [2026/10/03 18:14] (current) – [8. Publish it through NPM] admin
Line 5: Line 5:
 This guide uses Nginx Proxy Manager (NPM), which is Nginx with a web UI and automatic Let's Encrypt certificates. It's the fastest route to HTTPS subdomains. This guide uses Nginx Proxy Manager (NPM), which is Nginx with a web UI and automatic Let's Encrypt certificates. It's the fastest route to HTTPS subdomains.
  
-1. Prerequisites+==== 1. Prerequisites ==== 
   * A Linux server (Ubuntu/Debian VM, VPS, or homelab box) with a static LAN IP or public IP   * A Linux server (Ubuntu/Debian VM, VPS, or homelab box) with a static LAN IP or public IP
   * A domain you control (examples below use example.com)   * A domain you control (examples below use example.com)
Line 11: Line 12:
   * A firewall that allows 22, 80, 443 traffic   * A firewall that allows 22, 80, 443 traffic
  
-2. Install Docker+==== 2. Install Docker ====
  
-''curl -fsSL https://get.docker.com | sh+<code english install_docker.md> 
 +curl -fsSL https://get.docker.com | sh
 sudo usermod -aG docker $USER sudo usermod -aG docker $USER
 newgrp docker newgrp docker
-docker compose version   # confirm Compose v2 is present''+docker compose version   # confirm Compose v2 is present 
 +</code> 
 + 
 +==== 3. Install Portainer ==== 
 + 
 +<code english install_portainer.md> 
 +docker volume create portainer_data docker run -d --name portainer --restart=always \   -p 9443:9443 \   -v /var/run/docker.sock:/var/run/docker.sock \   -v portainer_data:/data \   portainer/portainer-ce:latest 
 +</code> 
 + 
 +Open [[https://SERVER-IP:9443]] and create the admin account before proceeding. The setup window times out after a few minutes. Choose the local environment. 
 + 
 +==== 4. Create a shared proxy network ==== 
 + 
 +Every web app joins this network so NPM can reach it by container name, with no host ports published. 
 + 
 +In Portainer: Networks → Add network → name ''proxy'', driver ''bridge''. 
 + 
 +Or via CLI: ''docker network create proxy'' 
 + 
 +==== 5. Deploy Nginx Proxy Manager as a Portainer stack ==== 
 + 
 +Stacks → Add stack → name ''npm'' → Web editor: 
 + 
 +<code english install_nginx_pm.md> 
 +services: 
 +  npm: 
 +    image: jc21/nginx-proxy-manager:latest 
 +    container_name: npm 
 +    restart: unless-stopped 
 +    ports: 
 +      - "80:80" 
 +      - "443:443" 
 +      - "81:81"        # admin UI; restrict to LAN 
 +    volumes: 
 +      - npm_data:/data 
 +      - npm_letsencrypt:/etc/letsencrypt 
 +    networks: 
 +      - proxy 
 + 
 +volumes: 
 +  npm_data: 
 +  npm_letsencrypt: 
 + 
 +networks: 
 +  proxy: 
 +    external: true 
 +   
 +</code> 
 + 
 +Click Deploy the stack. Then visit ''[[http://SERVER-IP:81]]'' and log in with ''admin@example.com'' / ''changeme''. You'll be prompted to change both right away. 
 + 
 +==== 6. Set up DNS ==== 
 + 
 +At your registrar or DNS host (Cloudflare, Namecheap, etc.): 
 + 
 +^ Type ^ Name ^ Value ^ 
 +| A | ''@'' (optional) | your public IP | 
 +| A | ''*'' (wildcard) | your public IP | 
 + 
 +A wildcard record means every new app subdomain works without touching DNS again. If your home IP changes, use a dynamic DNS updater (e.g., the Cloudflare DDNS container). 
 + 
 +==== 7. Deploy an app with Compose (via Portainer) ==== 
 + 
 +Stacks → Add stack. Paste the compose file, or use the Repository option to pull one from Git. Example, Uptime Kuma: 
 + 
 +<code -> 
 +services: 
 +  kuma: 
 +    image: louislam/uptime-kuma:1 
 +    container_name: kuma 
 +    restart: unless-stopped 
 +    volumes: 
 +      - kuma_data:/app/data 
 +    networks: 
 +      - proxy 
 + 
 +volumes: 
 +  kuma_data: 
 + 
 +networks: 
 +  proxy: 
 +    external: true 
 +</code> 
 + 
 +Key pattern for any app: 
 + 
 +  * Attach it to the ''proxy'' network. 
 +  * **Don't** publish ports. NPM reaches it internally. 
 +  * Note the app's internal port (Kuma: 3001; check the image docs). 
 +  * If the app has a database, put the DB on a private internal network and only the web container on ''proxy'': 
 + 
 +<code -> 
 +services: 
 +  web: 
 +    networks: [proxy, internal] 
 +  db: 
 +    networks: [internal] 
 +networks: 
 +  proxy: 
 +    external: true 
 +  internal: 
 +</code> 
 + 
 +Use Portainer's **Environment variables** section for secrets instead of hardcoding them. 
 + 
 +==== 8. Publish it through NPM ==== 
 + 
 +In NPM: **Hosts → Proxy Hosts → Add Proxy Host** 
 + 
 +  * **Domain Names:** ''kuma.example.com'' 
 +  * **Scheme:** ''http'' 
 +  * **Forward Hostname/IP:** ''kuma'' (the container name) 
 +  * **Forward Port:** ''3001'' 
 +  * Enable **Block Common Exploits** and **Websockets Support** (needed by many modern apps) 
 + 
 +**SSL tab:** 
 + 
 +  * Request a new Let's Encrypt certificate 
 +  * Enable **Force SSL** and **HTTP/2** 
 +  * Agree to the terms and save 
 + 
 +Browse to ''[[https://kuma.example.com]]''. 
 + 
 +==== 9. Repeat for each new app ==== 
 + 
 +  - Deploy a new stack on the ''proxy'' network. 
 +  - Add a Proxy Host with the container name and port. 
 +  - Issue the certificate. 
 + 
 +==== 10. Hardening and upkeep ==== 
 + 
 +  * Close port 81 and 9443 to the internet. Reach them via LAN or VPN (WireGuard/Tailscale), or put them behind an NPM **Access List**. 
 +  * Enable 2FA on NPM and Portainer. 
 +  * Pin image versions ('':1.2.3'' rather than '':latest'') for stability, and update deliberately via **Stacks → Pull and redeploy**. 
 +  * Back up the named volumes (''npm_data'', ''npm_letsencrypt'', and each app's data) plus your compose files. Keep the compose files in a Git repo. 
 +  * Keep the host patched (''unattended-upgrades'') and consider ''fail2ban'' or Cloudflare proxying in front. 
 + 
 +==== 11. Troubleshooting ====
  
-3. Install Portainer+^ Symptom ^ Likely cause ^ 
 +| 502 Bad Gateway | Wrong container name/port, or app not on the ''proxy'' network | 
 +| Cert request fails | DNS not pointing at you yet, ports 80/443 not forwarded, or ISP blocks 80 (use DNS challenge) | 
 +| Works on LAN, not outside | Router port forward or NAT hairpin issue; test from mobile data | 
 +| App loads but login/redirects break | Enable Websockets; set the app's "base URL" or "trusted proxy" setting to the public HTTPS URL | 
 +| Container can't resolve another | They don't share a network; check with ''docker network inspect proxy'' |
  
-''docker volume create portainer_data 
-docker run -d --name portainer --restart=always \ 
-  -p 9443:9443 \ 
-  -v /var/run/docker.sock:/var/run/docker.sock \ 
-  -v portainer_data:/data \ 
-  portainer/portainer-ce:latest'' 
  
creating_docker-compose_applications.1791061327.txt.gz · Last modified: by admin