keepcalculator

06 Numbers and Powers

Access GUI Apps Remotely with Docker and Caddy

Card No. 06·71991 · Updated · Standard formula, shown below

This guide shows you how to securely access graphical applications (like a browser, IDE, or desktop environment) running in a Docker container from anywhere, using Caddy as a reverse proxy with automatic HTTPS. You’ll set up a container with a web-based remote desktop, expose it through Caddy, and connect via your browser.

What You’ll Need

  • A Linux server (or any machine with Docker) that is reachable on the internet.
  • A domain name pointing to your server’s public IP address.
  • Docker and Docker Compose installed on that server.
  • Ports 80 and 443 open in your firewall.
  • Basic familiarity with the command line and text editing.

Step-by-Step

  1. Create a project directory – On your server, run mkdir ~/remote-gui && cd ~/remote-gui to keep everything in one place.
  2. Create a docker-compose.yml file – Use a text editor (like nano) to create a file with the following content. This example uses the linuxserver/code-server image, which gives you VS Code in the browser – a good starting point. Replace your-domain.com with your actual domain.
    version: "3"
    services:
      code-server:
        image: lscr.io/linuxserver/code-server:latest
        container_name: code-server
        environment:
          - PUID=1000
          - PGID=1000
          - TZ=Etc/UTC
          - PASSWORD=yourpassword
        volumes:
          - ./config:/config
        ports:
          - "8443:8443"
        restart: unless-stopped
      caddy:
        image: caddy:2
        container_name: caddy
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - ./Caddyfile:/etc/caddy/Caddyfile
          - caddy_data:/data
        restart: unless-stopped
    volumes:
      caddy_data:
    
  3. Create the Caddyfile – In the same directory, create a file named Caddyfile with this content:
    your-domain.com {
        reverse_proxy code-server:8443
    }
    

    Caddy will automatically obtain and renew a Let’s Encrypt SSL certificate for your domain.

  4. Start the containers – Run docker-compose up -d to pull the images and start both services in the background.
  5. Verify the setup – Wait a minute for Caddy to get the certificate, then open https://your-domain.com in your browser. You should see the code-server login page. Enter the password you set in the compose file.
  6. Access your app – You now have a full VS Code environment in the browser, secured with HTTPS. You can use it from any device.

Common Mistakes

  • Using the wrong port – The ports section in the compose file maps the container’s port to the host. Make sure the Caddyfile points to the internal port (e.g., 8443), not the host port.
  • Forgetting to open firewall ports – If you can’t reach the site, check that ports 80 and 443 are open on your server’s firewall and in your cloud provider’s security group.
  • DNS not pointing to your server – Ensure your domain’s A record points to your server’s public IP. Use dig your-domain.com to check.
  • Using HTTP instead of HTTPS – Caddy redirects HTTP to HTTPS automatically. If you type http:// you’ll be redirected.

Tips

  • Use a strong password – Set a long, random password in the compose file. Better yet, use Caddy’s built-in authentication (basic_auth) for an extra layer.
  • Limit access by IP – In the Caddyfile, you can add @blocked not remote_ip your-ip and then respond @blocked 403 to restrict access to your home IP.
  • Use a subdomain – Instead of a bare domain, use something like code.your-domain.com to keep things organized.
  • Back up your config – The ./config folder contains your settings and files. Back it up regularly.
  • Update images – Periodically run docker-compose pull and docker-compose up -d to get the latest security patches.

Troubleshooting

Can’t connect to the site – Check if the containers are running: docker-compose ps. If they are, check Caddy logs: docker-compose logs caddy. Common issues: DNS not propagated, firewall blocking, or Caddy unable to obtain a certificate (port 80 must be open).

Certificate error – If you see a warning, wait a few minutes and refresh. If it persists, verify your domain points to the correct IP and that port 80 is reachable from the internet.

App loads but shows a blank page – This often happens when the app tries to use WebSockets or other features that Caddy needs to proxy. In the Caddyfile, add websocket to the proxy line (though Caddy 2 does this automatically for most cases). If using a different app, check its documentation for required proxy headers.

Password not working – Make sure you set PASSWORD in the environment section of the compose file. If you changed it, recreate the container with docker-compose up -d --force-recreate.

Everything works but it’s slow – This is normal for remote desktops. Consider using a lighter app (like a terminal-based IDE) or a more powerful server.

Frequently Asked Questions

Can I use this with any GUI app? – Yes, as long as the app provides a web interface. For desktop environments, use images like linuxserver/webtop which gives a full desktop in the browser.

Is this secure? – Yes, Caddy provides HTTPS encryption. However, you should still use a strong password and consider additional authentication layers.

Do I need a domain name? – Not strictly, but Caddy’s automatic HTTPS requires a domain. If you don’t have one, you can use a free service like DuckDNS or use Caddy with an IP address (but then you’ll need to handle certificates manually).

Can I access the app from my phone? – Yes, any device with a modern browser works. The interface may be small, but it’s usable.

How do I stop the services? – Run docker-compose down from the project directory. This stops and removes the containers, but your config data persists.

What if I want to expose multiple apps? – Add more services to the compose file, each with its own port, and add corresponding entries in the Caddyfile using different subdomains.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →