Local domain in hosts file does not work with docker

1. The problem I’m having:

I’m running caddy in docker with php-fpm and everything is working fine as long as I stick to localhost in the Caddyfile. I will try to run wordpress on the server so I would like to type in a local domain defined in the /etc/hosts file for example https://my-domain.loc.

In /etc/hosts I have an entry → 127.0.0.1 localhost my-domain.loc

Not working Caddyfile: ========================================
my-domain.loc:443 {
php_fastcgi wp-fpm:9000
file_server
}

But if I change my-domain.loc:443 to localhost:443 and type in https://localhost in my browser it works.

Docker compose file extract ========================
services:
caddy:
container_name: caddy-server275
image: caddy:2.7.5
restart: unless-stopped
depends_on:
- mariadb
- phpfpm

cap_add:
  - NET_ADMIN
ports:
  - "80:80"
  - "443:443"
  - "443:443/udp"
volumes:
  - $PWD/Caddyfile:/etc/caddy/Caddyfile
  - /var/www/my-domain.loc:/srv
  - caddy_data:/data
  - caddy_config:/config
networks:
    - wp-net

Am I missing something here?

Thanks

dinbox

2. Error messages and/or full log output:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

3. Caddy version:

4. How I installed and ran Caddy:

a. System environment:

b. Command:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

5. Links to relevant resources:

You’ll need to add tls internal to your site for Caddy to issue a cert using its own CA, like it automatically does for localhost. Or, just use my-domain.localhost (i.e. *.localhost) which Caddy also automatically enables internal for.

Ok will try that, thanks alot!

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