Setup caddy with docker on local machine

1. Caddy version (latest):

2. How I run Caddy:

In docker on local machine

a. System environment:

windows 10 wsl2

b. Command:

N/A

c. docker.compose file:

  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./site:/srv
      - caddy_data:/data
      - caddy_config:/config
volumes:
  caddy_data:
  caddy_config:

d. My complete Caddyfile

localhost

respond "hello world"

3. The problem I’m having:

I’d like to get a simple hello world example going.
Entering https://localhost in the browser
will only show “This site can not be reached”

1 Like

I’ve seen in the past that WSL has trouble being mapped to localhost on the host machine. This issue might be relevant:

https://github.com/microsoft/WSL/issues/4636

Also, note that when running in Docker, Caddy can’t install the root CA cert it generates to your system trust stores, because it’s isolated from the rest of your system. So you’ll likely need to extract the certificate from the container to do so. It should be found in /data/pki/authorities/local/root.crt inside the container.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.