installation-docker.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. .. _installation docker:
  2. ================
  3. Docker Container
  4. ================
  5. .. _ENTRYPOINT: https://docs.docker.com/engine/reference/builder/#entrypoint
  6. .. _searxng/searxng @dockerhub: https://hub.docker.com/r/searxng/searxng
  7. .. _searxng-docker: https://github.com/searxng/searxng-docker
  8. .. _[caddy]: https://hub.docker.com/_/caddy
  9. .. _Redis: https://redis.io/
  10. ----
  11. .. sidebar:: info
  12. - `searxng/searxng @dockerhub`_
  13. - :origin:`Dockerfile`
  14. - `Docker overview <https://docs.docker.com/get-started/overview>`_
  15. - `Docker Cheat Sheet <https://docs.docker.com/get-started/docker_cheatsheet.pdf>`_
  16. - `Alpine Linux <https://alpinelinux.org>`_
  17. `(wiki) <https://en.wikipedia.org/wiki/Alpine_Linux>`__
  18. `apt packages <https://pkgs.alpinelinux.org/packages>`_
  19. - Alpine's ``/bin/sh`` is :man:`dash`
  20. **If you intend to create a public instance using Docker, use our well maintained
  21. docker container**
  22. - `searxng/searxng @dockerhub`_.
  23. .. sidebar:: hint
  24. The rest of this article is of interest only to those who want to create and
  25. maintain their own Docker images.
  26. The sources are hosted at searxng-docker_ and the container includes:
  27. - a HTTPS reverse proxy `[caddy]`_ and
  28. - a Redis_ DB
  29. The `default SearXNG setup <https://github.com/searxng/searxng-docker/blob/master/searxng/settings.yml>`_
  30. of this container:
  31. - enables :ref:`limiter <limiter>` to protect against bots
  32. - enables :ref:`image proxy <image_proxy>` for better privacy
  33. - enables :ref:`cache busting <static_use_hash>` to save bandwidth
  34. ----
  35. Get Docker
  36. ==========
  37. If you plan to build and maintain a docker image by yourself, make sure you have
  38. `Docker installed <https://docs.docker.com/get-docker/>`_. On Linux don't
  39. forget to add your user to the docker group (log out and log back in so that
  40. your group membership is re-evaluated):
  41. .. code:: sh
  42. $ sudo usermod -a -G docker $USER
  43. searxng/searxng
  44. ===============
  45. .. sidebar:: ``docker run``
  46. - `-\-rm <https://docs.docker.com/engine/reference/run/#clean-up---rm>`__
  47. automatically clean up when container exits
  48. - `-d <https://docs.docker.com/engine/reference/run/#detached--d>`__ start
  49. detached container
  50. - `-v <https://docs.docker.com/engine/reference/run/#volume-shared-filesystems>`__
  51. mount volume ``HOST:CONTAINER``
  52. The docker image is based on :origin:`Dockerfile` and available from
  53. `searxng/searxng @dockerhub`_. Using the docker image is quite easy, for
  54. instance you can pull the `searxng/searxng @dockerhub`_ image and deploy a local
  55. instance using `docker run <https://docs.docker.com/engine/reference/run/>`_:
  56. .. code:: sh
  57. $ mkdir my-instance
  58. $ cd my-instance
  59. $ export PORT=8080
  60. $ docker pull searxng/searxng
  61. $ docker run --rm \
  62. -d -p ${PORT}:8080 \
  63. -v "${PWD}/searxng:/etc/searxng" \
  64. -e "BASE_URL=http://localhost:$PORT/" \
  65. -e "INSTANCE_NAME=my-instance" \
  66. searxng/searxng
  67. 2f998.... # container's ID
  68. The environment variables UWSGI_WORKERS and UWSGI_THREADS overwrite the default
  69. number of UWSGI processes and UWSGI threads specified in `/etc/searxng/uwsgi.ini`.
  70. Open your WEB browser and visit the URL:
  71. .. code:: sh
  72. $ xdg-open "http://localhost:$PORT"
  73. Inside ``${PWD}/searxng``, you will find ``settings.yml`` and ``uwsgi.ini``. You
  74. can modify these files according to your needs and restart the Docker image.
  75. .. code:: sh
  76. $ docker container restart 2f998
  77. Use command ``container ls`` to list running containers, add flag `-a
  78. <https://docs.docker.com/engine/reference/commandline/container_ls>`__ to list
  79. exited containers also. With ``container stop`` a running container can be
  80. stopped. To get rid of a container use ``container rm``:
  81. .. code:: sh
  82. $ docker container ls
  83. CONTAINER ID IMAGE COMMAND CREATED ...
  84. 2f998d725993 searxng/searxng "/sbin/tini -- /usr/…" 7 minutes ago ...
  85. $ docker container stop 2f998
  86. $ docker container rm 2f998
  87. .. sidebar:: Warning
  88. This might remove all docker items, not only those from SearXNG.
  89. If you won't use docker anymore and want to get rid of all containers & images
  90. use the following *prune* command:
  91. .. code:: sh
  92. $ docker stop $(docker ps -aq) # stop all containers
  93. $ docker system prune # make some housekeeping
  94. $ docker rmi -f $(docker images -q) # drop all images
  95. shell inside container
  96. ----------------------
  97. .. sidebar:: Bashism
  98. - `A tale of two shells: bash or dash <https://lwn.net/Articles/343924/>`_
  99. - `How to make bash scripts work in dash <http://mywiki.wooledge.org/Bashism>`_
  100. - `Checking for Bashisms <https://dev.to/bowmanjd/writing-bash-scripts-that-are-not-only-bash-checking-for-bashisms-and-testing-with-dash-1bli>`_
  101. To open a shell inside the container:
  102. .. code:: sh
  103. $ docker exec -it 2f998 sh
  104. Build the image
  105. ===============
  106. It's also possible to build SearXNG from the embedded :origin:`Dockerfile`::
  107. $ git clone https://github.com/searxng/searxng.git
  108. $ cd searxng
  109. $ make docker.build
  110. ...
  111. Successfully built 49586c016434
  112. Successfully tagged searxng/searxng:latest
  113. Successfully tagged searxng/searxng:1.0.0-209-9c823800-dirty
  114. $ docker images
  115. REPOSITORY TAG IMAGE ID CREATED SIZE
  116. searxng/searxng 1.0.0-209-9c823800-dirty 49586c016434 13 minutes ago 308MB
  117. searxng/searxng latest 49586c016434 13 minutes ago 308MB
  118. alpine 3.13 6dbb9cc54074 3 weeks ago 5.61MB
  119. Command line
  120. ============
  121. .. sidebar:: docker run
  122. Use flags ``-it`` for `interactive processes
  123. <https://docs.docker.com/engine/reference/run/#foreground>`__.
  124. In the :origin:`Dockerfile` the ENTRYPOINT_ is defined as
  125. :origin:`container/docker-entrypoint.sh`
  126. .. code:: sh
  127. docker run --rm -it searxng/searxng -h
  128. .. program-output:: ../container/docker-entrypoint.sh -h