weserv / images

Source code of wsrv.nl (formerly images.weserv.nl), to be used on your own server(s).
https://wsrv.nl/
BSD 3-Clause "New" or "Revised" License
1.84k stars 188 forks source link

Docker Selfhosted Setup #423

Closed QuadStingray closed 1 week ago

QuadStingray commented 1 week ago

I want to host an Instance of weserv/images on my internal Kubernetes Cluster.

How can I setup an instance without any domain limitations and DNS Server from device usage, for example on local device based development.

docker run -d -p 8081:80 --shm-size=1gb --name=weserv ghcr.io/weserv/images:5.x
curl -v http://localhost:8081/\?url=http://host.docker.internal:8080/api/files/D8270076110FCEAE93FAC573CFBCC031F7B6A0FD

The curl doesn`t work with error.

{"status":"error","code":404,"message":"The hostname of the origin is unresolvable (DNS) or blocked by policy."}

If i connect to docker container this curl is working.

curl http://host.docker.internal:8080/api/files/D8270076110FCEAE93FAC573CFBCC031F7B6A0FD

An other question is how to disable caching on my self hosted instance?

Thanks for your help!

kleisauke commented 1 week ago

By default, Google's open DNS server (8.8.8.8) is used to resolve DNS queries. However, to resolve host.docker.internal, you may need to use Docker's embedded DNS server within the nginx configuration, see: https://github.com/weserv/images/issues/206#issuecomment-1752740666

To disable any caching, you can use the the imagesweserv-no-cache.conf config, see: https://github.com/weserv/images/issues/354#issuecomment-1221544455

The following Dockerfile combines these approaches:

# Usage: docker build --build-arg DNS_SERVER=127.0.0.11 -t weserv/images .
FROM ghcr.io/weserv/images:5.x

ARG DNS_SERVER=1.1.1.1

RUN cp ngx_conf/imagesweserv-no-cache.conf /etc/nginx/imagesweserv.conf \
    && sed -i "/resolver /s/[0-9].*/$DNS_SERVER;/" /etc/nginx/imagesweserv.conf
QuadStingray commented 1 week ago

Thanks! 👍🏻

QuadStingray commented 1 day ago

To set the DNS Server IP to 127.0.0.11 did not work for me. So I read the DNS Server now from /etc/resolv.conf on server startup.

So just for Documentation and if someone else has the same Issue here my Dockerfile:

FROM ghcr.io/weserv/images:5.x

RUN rm -rf /etc/nginx/imagesweserv.conf \
    && cp ngx_conf/imagesweserv-no-cache.conf /etc/nginx/imagesweserv.conf

CMD DNS_SERVER=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}' | head) ;\
    sed -i "/resolver /s/[0-9].*/$DNS_SERVER;/" /etc/nginx/imagesweserv.conf; \
    nginx -g "daemon off;"