Hello World in Caddy using Docker

Author

Gurleen Sethi on 18 June 2023

Hello World in Caddy using Docker
Code Repository
Code realted to this article is stored in this repository.

In this article I am going to show you how to run a simple webserver using Caddy and Docker.

Caddyfile #

Let's write a Caddyfile that returns a simple "Hello World".

:80 {
	respond "Hello World"
}
Caddyfile

Now using docker, run the caddy:latest container while mounting the above Caddyfile as a volume.

docker run --rm --name caddy -p 8080:80 -v ${PWD}/Caddyfile:/etc/caddy/Caddyfile caddy:latest

Docker Compose #

When developing locally you would want to run Caddy using Docker Compose. Using the above Caddyfile, let's write a docker-compose.yaml file.

version: '3.8'

services:
  caddy:
    image: caddy:latest
    ports:
      - 8080:80
    volumes:
      - ${PWD}/Caddyfile:/etc/caddy/Caddyfile
docker-compose.yaml

Now run using docker compose.

docker compose up -d

Once the container is running test it out using curl.

curl localhost:8080
Hello World

Reference Links

Caddy
Docker Compose

Table of Contents
Code Repository
Code realted to this article is stored in this repository.
Subscribe via email

Get notified once/twice per month when new articles are published.

Byte Byte Go Affiliate
TheDeveloperCafe
Copyright © 2022 - 2023 TheDeveloperCafe.
The Go gopher was designed by Renee French.