Skip to main content
  1. Posts/

How to Install Caddy with Docker

·428 words·3 mins· loading · loading · ·
categories: Tutorial
tags: Tutorial Docker Ubuntu Linux Mint Install

Caddy is the best and simplest web server like that of Nginx and Apache. I’ve tried both of the latter and to say it’s the simplest is no joke. I just add my domain to its Caddyfile and where it’ll reverse proxy onto and tada, it’s done. It even takes care of SSL certificate automatically so you don’t have to run the certbot yourself!

Wonderful, yes, but don’t forget to remove the existing SSL certificate with sudo certbot delete (or manually add the path with Caddyfile’s TLS). Otherwise, you’ll be spamming ACME for certification and you’ll end up having to wait a day to get it again. I did this twice. The first time I didn’t know why my site was still on HTTP and the second time, because Caddy couldn’t access Apache’s SSL certificate.

Expand this and run it in a terminal for those who are lazy and just want to get it done in one command.
curl -L s.revonzev.com/install-caddy-docker-curl | bash

Or the full command:

curl -L https://git.revonzev.com/revon/r_blog/raw/branch/main/docker_compose/caddy/docker-compose.yml > ./docker-compose.yml && \
mkdir ./container_config && \
curl -L https://git.revonzev.com/revon/r_blog/raw/branch/main/docker_compose/caddy/container_config/Caddyfile > ./container_config/Caddyfile && \
docker network create "reverseproxy-nw" ; \
docker compose up -d

Then open hello-world.localhost in your browser to see if it is successful.

A guide to installing Docker in Linux Mint is here.

Anyway, here’s my docker-compose for Caddy:

services:
  caddy:
    image: caddy:latest
    container_name: caddy
    restart: unless-stopped
    security_opt:
      - label:disable
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./container_config:/etc/caddy
      - ./site:/srv
      - ./caddy_data:/data
      - ./caddy_config:/config
      - ./caddy_log:/var/log/caddy
      - /etc/localtime:/etc/localtime:ro
    networks:
      - reverseproxy-nw


networks:
  reverseproxy-nw:
    external: true

Don’t forget to add Caddy’s Caddyfile. Create a new folder named container_config and make a new file named Caddyfile inside of it with the below code in it.

http://hello-world.localhost {
  respond "Hello World!"
}

You can change the http://hello-world.localhost to your own domain. Caddy will not turn HTTP into HTTPS for sites with http://... e.g. http://example.com. Caddy will, however, automatically turn a site like example.com (without the http://) into HTTPS.

One last step to do is to add the reverseproxy-nw Docker network by running this in the terminal:

docker network create "reverseproxy-nw"

This is done so Caddy can access other docker containers that are connected to reverseproxy-nw Docker network. E.g.:

http://s.localhost {
  reverse_proxy chhoto-url:4567
}

chhoto-url is the Docker container’s name, while 4567 is its port.

Now run this command to start the docker container:

docker compose up -d

Go to hello-world.localhost in your browser to see if it is working or not. Mine certainly did.

The tutorial I find most helpful in installing caddy was this

Revon Zev
Author
Revon Zev
A game streamer on Twitch, and a game VTuber on YouTube with a hobby of creating art and programming.

Related

How to Install Docker on Linux Mint in One Command
·299 words·2 mins· loading · loading
categories: Tutorial
tags: Tutorial Docker Ubuntu Linux Mint Install
How to Self-Host Outline Alongside Caddy
·744 words·4 mins· loading · loading
categories: Tutorial
tags: Tutorial Docker Ubuntu Linux Mint Caddy Install
Fist Post
·480 words·3 mins· loading · loading
categories: Uncategorized
tags: Other