Error obtaining home directory, please define environment variable HOME. caddy2 cannot run

1. Caddy version (caddy version):

v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=

2. How I run Caddy:

install caddy bin

a. System environment:

alpine:edge
dockerfile deploy container

b. Command:

/usr/local/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. Service/unit/compose file:

FROM alpine:edge

RUN  apk update && \
     apk add --no-cache --virtual .build-deps ca-certificates nss-tools curl && \
     mkdir /tmp/v2ray && \
     mkdir /tmp/caddy && \
     curl -L -H "Cache-Control: no-cache" -o /tmp/v2ray/v2ray.zip https://github.com/v2fly/v2ray-core/releases/latest/download/v2ray-linux-64.zip && \
     unzip /tmp/v2ray/v2ray.zip -d /tmp/v2ray && \
     install -m 755 /tmp/v2ray/v2ray /usr/local/bin/v2ray && \
     install -m 755 /tmp/v2ray/v2ctl /usr/local/bin/v2ctl && \
     v2ray -version && \
     curl -L -H "Cache-Control: no-cache" -o /tmp/caddy/caddy https://github.com/caddyserver/caddy/releases/download/v2.4.3/caddy_2.4.3_linux_arm64.tar.gz && \
     tar -zxvf /tmp/caddy/caddy.tar.gz -C /tmp/caddy && \
     install -m 755 /tmp/caddy/caddy /usr/local/bin/caddy && \
     caddy version && \
     rm -rf /tmp/caddy && \
     rm -rf /tmp/v2ray && \
     rm -rf /var/cache/apk/* && \
     apk del .build-deps

COPY etc/ /conf
ADD config.sh /config.sh
RUN chmod +x /config.sh
CMD /config.sh

d. My complete Caddyfile or JSON config:

I have deleted parts of the files for confidentiality reasons

:$PORT

root * ******
file_server browse

tls internal

header {
    Permissions-Policy interest-cohort=()
    Strict-Transport-Security max-age=31536000;
    X-Robots-Tag none
    X-Content-Type-Options nosniff
    X-Frame-Options DENY
    Referrer-Policy no-referrer-when-downgrade
}

basicauth ****** {
    ****** ******
}

@websocket****** {
    header Connection *Upgrade*
    header Upgrade    websocket
    path ******
}
reverse_proxy @websocket****** ******

3. The problem I’m having:

error obtaining home directory, please define environment variable HOME.

4. Error messages and/or full log output:

{“level”:“warn”,“ts”:1629167856.1931417,“msg”:“unable to determine directory for user configuration; falling back to current directory”,“error”:“neither $XDG_CONFIG_HOME nor $HOME are defined”}
Error obtaining home directory, please define environment variable HOME.

5. What I already tried:

using caddy version v2.3 ~ v2.1

Still prompted Error obtaining home directory, please define environment variable HOME.

6. Links to relevant resources:

This means the $HOME environment variable isn’t set.

You can verify this easily enough. What is the output when you add the --environ flag to your run command?

$home variable set to caddy work folder or caddy webroot folder ?

I strongly recommend using our official Docker image, which is properly set up. See it on Docker Hub

1 Like

Try adding the following code in the dockerfile (in addition, please use the official docker image as much as possible. It is not a good idea to run v2ray and caddy in the same docker container).

祝你好运 :crazy_face:

# See https://caddyserver.com/docs/conventions#file-locations for details
ENV XDG_CONFIG_HOME /config
ENV XDG_DATA_HOME /data
1 Like

XDG_CONFIG_HOME & XDG_DATA_HOME error clear.
but still prompted variable HOME error

docker image it works

ta

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