Open nemanjam opened 1 year ago
I've tried exposing Dokku container directly without Traefik but I get exact same error, its not the reason.
ports:
- '3022:22'
- '443:443'
- '80:80'
Get the same issue when running dokku inside of container.
By looking into the code for build docker run command: https://github.com/dokku/dokku-letsencrypt/blob/5dc9bf5d055b5ef19f34e23eded8641b5e5ef043/internal-functions#L42-L48
The --env-file
parameter is using host folder, not the folder inside of dokku container.
Because of docker run
requires loading this env file to construct docker API call, before sending request to docker daemon, it get "no such file or directory" error. --env-file
argument is not like volume mount, should use dokku side file path.
My current workaround is to exec into dokku container, and create symbo-link folder to let dokku container docker client can read file with same location in host level. This may recreate again after dokku container recreated (like upgrading).
@feng-zh Care to share code for symlink inside the dokku container. Currently stuck with problem
@feng-zh Care to share code for symlink inside the dokku container. Currently stuck with problem
@paschaldev this will depend on what host folder you are mapping to container dokku folder "/mnt/dokku".
Here is the example assume you are mapping host folder "/path/to/host/dokku-data" into dokku container "/mnt/dokku" folder, then you need;
# inside of dokku container
mkdir -p /path/to/host
cd /path/to/host
ln -s /mnt/dokku dokku-data
# verify the dokku folder is found by using host folder path inside of dokku container
ls /path/to/host/dokku-data/home/dokku
This workaround helped me get further, but then another issues crops up:
acme: error presenting token: could not create required directories in webroot for HTTP challenge: mkdir /webroot/.well-known: permission denied
Seems like dokku-letsencrypt is not really tested with docker. The issue seems to be that letsencrypt is trying to mount the container's data directory, not the host data directory.
The workaround is to make a symlink on the host like this (assuming /opt/dokku
is the /mnt/dokku
source):
ln -s /opt/dokku/var/lib/dokku /var/lib/dokku
Setting the symlink I get
=====> Enabling letsencrypt for APP
-----> Enabling ACME proxy for APP...
ok: run: nginx: (pid 70) 630555s
-----> Getting letsencrypt certificate for APP via HTTP-01
- Domain 'DOMAIN'
2024/09/17 14:00:01 No key found for account EMAIL. Generating a P256 key.
2024/09/17 14:00:01 Could not check/create directory for account EMAIL: mkdir /certs/accounts: permission denied
-----> Certificate retrieval failed!
-----> Disabling ACME proxy for APP...
ok: run: nginx: (pid 70) 630556s
! Failed to setup letsencrypt
! Check log output for further information on failure
After that I made these directories writable from host:
(Dont actually use 777 here, I'm just debugging)
chmod 777 /var/lib/dokku/home/dokku/APP/letsencrypt/certs/HASH/
chmod -R 777 /var/lib/dokku/data/letsencrypt/APP/
Which solved the "cant create directory" stuff although I still can't get this to work
=====> Enabling letsencrypt for APP
-----> Enabling ACME proxy for APP...
ok: run: nginx: (pid 70) 702731s
-----> Getting letsencrypt certificate for APP via HTTP-01
- Domain 'DOMAIN'
DOCKERS: docker run --rm --env-file /var/lib/dokku/home/dokku/APP/letsencrypt/certs/HASH/docker.env --user 200:200 -v /var/lib/dokku/home/dokku/APP/letsencrypt/certs/HASH:/certs -v /var/lib/dokku/data/letsencrypt/APP:/webroot goacme/lego:v4.9.1 --http --http.webroot /webroot --pem --accept-tos --cert.timeout 2592000 --path /certs --server https://acme-v02.api.letsencrypt.org/directory --email EMAIL --domains DOMAIN run
2024/09/18 10:02:57 [INFO] [DOMAIN] acme: Obtaining bundled SAN certificate
2024/09/18 10:02:58 [INFO] [DOMAIN] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz-v3/ID
2024/09/18 10:02:58 [INFO] [DOMAIN] acme: Could not find solver for: tls-alpn-01
2024/09/18 10:02:58 [INFO] [DOMAIN] acme: use http-01 solver
2024/09/18 10:02:58 [INFO] [DOMAIN] acme: Trying to solve HTTP-01
2024/09/18 10:03:03 [INFO] Deactivating auth: https://acme-v02.api.letsencrypt.org/acme/authz-v3/ID
2024/09/18 10:03:03 Could not obtain certificates:
error: one or more domains had a problem:
[DOMAIN] acme: error: 403 :: urn:ietf:params:acme:error:unauthorized :: IP: Invalid response from http://DOMAIN/.well-known/acme-challenge/CHALLENGE_KEY: 404
-----> Certificate retrieval failed!
-----> Disabling ACME proxy for APP...
ok: run: nginx: (pid 70) 702738s
! Failed to setup letsencrypt
! Check log output for further information on failure
The file also gets correctly created (and removed) just not accessible for some reason
When I try to enable letsencrypt it can't find
docker.env
file although it exists, I checked manually. Here is the error log.It's an empty file but it exists, here it is from the container:
And here it is from the host:
I use this
docker-compose.yml
:https://github.com/nemanjam/traefik-proxy/blob/main/apps/dokku/docker-compose.yml
dokku report nextjs-app: https://gist.github.com/nemanjam/1e66aa8683ea3535fe1a1ea1848f1dab
dokku ps:inspect nextjs-app: https://gist.github.com/nemanjam/629767d02b5493b8eeb42ee9171d8f55
~/traefik-proxy/apps/dokku$ tree -da .
: https://gist.github.com/nemanjam/6437f96ed522fb812e45ea5231ebe05a