Hello World in Caddy using Docker

Read more articles on Cloud, Caddy
github logo
Github Repository
Code for this articles is available on GitHub
Hello World in Caddy using Docker

Subscribe

Get updated 1 - 2 times a month when new articles are published, no spam ever.

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

Subscribe

Get updated 1 - 2 times a month when new articles are published, no spam ever.

    TheDeveloperCafe © 2022-2024