searxng/docs/admin/installation-docker.rst
Alexandre Flament bd3f526859
Docker: add UWSGI_WORKERS and UWSGI_THREAD environment variables (#2992)
* Docker: add UWSGI_WORKERS and UWSGI_THREAD.

UWSGI_WORKERS specifies the number of process.
UWSGI_THREADS specifies the number of threads.

The Docker convention is to specify the whole configuration
through environment variables. While not done in SearXNG, these two
additional variables allows admins to skip uwsgi.ini

In additional, https://github.com/searxng/preview-environments starts Docker
without additional files through searxng-helm-chat.
Each instance consumes 1Go of RAM which is a lot especially when there are a
lot of instances / pull requests.

* [scripts] add environments UWSGI_WORKERS and UWSGI_THREADS

- UWSGI_WORKERS specifies the number of process.
- UWSGI_THREADS specifies the number of threads.

Templates for uwsgi scripts can be tested by::

    UWSGI_WORKERS=8 UWSGI_THREADS=9 \
      ./utils/searxng.sh --cmd\
      eval "echo \"$(cat utils/templates/etc/uwsgi/*/searxng.ini*)\""\
      | grep "workers\|threads"

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

---------

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Co-authored-by: Markus Heiser <markus.heiser@darmarit.de>
2023-11-12 16:46:34 +00:00

6.2 KiB

Docker Container


If you intend to create a public instance using Docker, use our well maintained docker container

hint

The rest of this article is of interest only to those who want to create and maintain their own Docker images.

The sources are hosted at searxng-docker and the container includes:

The default SearXNG setup of this container:

  • enables limiter <limiter> to protect against bots
  • enables image proxy <image_proxy> for better privacy
  • enables cache busting <static_use_hash> to save bandwidth

Get Docker

If you plan to build and maintain a docker image by yourself, make sure you have Docker installed. On Linux don't forget to add your user to the docker group (log out and log back in so that your group membership is re-evaluated):

$ sudo usermod -a -G docker $USER

searxng/searxng

docker run

  • --rm automatically clean up when container exits
  • -d start detached container
  • -v mount volume HOST:CONTAINER

The docker image is based on Dockerfile and available from searxng/searxng @dockerhub. Using the docker image is quite easy, for instance you can pull the searxng/searxng @dockerhub image and deploy a local instance using docker run:

$ mkdir my-instance
$ cd my-instance
$ export PORT=8080
$ docker pull searxng/searxng
$ docker run --rm \
             -d -p ${PORT}:8080 \
             -v "${PWD}/searxng:/etc/searxng" \
             -e "BASE_URL=http://localhost:$PORT/" \
             -e "INSTANCE_NAME=my-instance" \
             searxng/searxng
2f998.... # container's ID

The environment variables UWSGI_WORKERS and UWSGI_THREADS overwrite the default number of UWSGI processes and UWSGI threads specified in /etc/searxng/uwsgi.ini.

Open your WEB browser and visit the URL:

$ xdg-open "http://localhost:$PORT"

Inside ${PWD}/searxng, you will find settings.yml and uwsgi.ini. You can modify these files according to your needs and restart the Docker image.

$ docker container restart 2f998

Use command container ls to list running containers, add flag -a to list exited containers also. With container stop a running container can be stopped. To get rid of a container use container rm:

$ docker container ls
CONTAINER ID   IMAGE             COMMAND                  CREATED         ...
2f998d725993   searxng/searxng   "/sbin/tini -- /usr/…"   7 minutes ago   ...

$ docker container stop 2f998
$ docker container rm 2f998

Warning

This might remove all docker items, not only those from SearXNG.

If you won't use docker anymore and want to get rid of all containers & images use the following prune command:

$ docker stop $(docker ps -aq)       # stop all containers
$ docker system prune                # make some housekeeping
$ docker rmi -f $(docker images -q)  # drop all images

shell inside container

Like in many other distributions, Alpine's /bin/sh is dash. Dash is meant to be POSIX-compliant. Compared to debian, in the Alpine image bash is not installed. The dockerfiles/docker-entrypoint.sh script is checked against dash (make tests.shell).

To open a shell inside the container:

$ docker exec -it 2f998 sh

Build the image

It's also possible to build SearXNG from the embedded Dockerfile:

$ git clone https://github.com/searxng/searxng.git
$ cd searxng
$ make docker.build
...
Successfully built 49586c016434
Successfully tagged searxng/searxng:latest
Successfully tagged searxng/searxng:1.0.0-209-9c823800-dirty

$ docker images
REPOSITORY        TAG                        IMAGE ID       CREATED          SIZE
searxng/searxng   1.0.0-209-9c823800-dirty   49586c016434   13 minutes ago   308MB
searxng/searxng   latest                     49586c016434   13 minutes ago   308MB
alpine            3.13                       6dbb9cc54074   3 weeks ago      5.61MB

Command line

docker run

Use flags -it for interactive processes.

In the Dockerfile the ENTRYPOINT is defined as dockerfiles/docker-entrypoint.sh

docker run --rm -it searxng/searxng -h

../dockerfiles/docker-entrypoint.sh -h