Skip to content

Environment Variables #343

Description

@samcro1967

I am trying to figure out how to use environment variables with Caddyfile. I saw on the caddy forum to add them as labels to the container and caddy will pick them up. I tried this and the variable is not being picked up by caddy. Environment variables for other services in docker-compose are working.

Does anything different need to be done with caddy-docker-proxy in the mix? Wanted to check here before I post to the forum.

docker-compose

  caddy:
    hostname: caddy    
    image: caddy220216
    container_name: caddy
    restart: always
    environment:
      - TZ=${TZ}
      - CADDY_DOCKER_CADDYFILE_PATH=/data/CaddyFile
      - email=${EMAIL}
    ports:
      - 8069:8069
      - 443:443
      - 2019:2019
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - "${docker}/caddy2/data:/data"
      - "${docker}/caddy2/config:/config"

.env file

EMAIL=user@mydomain.net

Caddyfile contents

{
	http_port	8069
	https_port	443
	email {env.EMAIL} #also tried {$EMAIL}
	debug
	log {
		output file /data/caddy.log
        level warn
		format console
    }

Caddyfile from container logs
{
http_port 8069
https_port 443
email ${EMAIL}
debug
log {
output file /data/caddy.log
level warn
format console
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions