installation-docker.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 bandwith
  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. Open your WEB browser and visit the URL:
  69. .. code:: sh
  70. $ xdg-open "http://localhost:$PORT"
  71. Inside ``${PWD}/searxng``, you will find ``settings.yml`` and ``uwsgi.ini``. You
  72. can modify these files according to your needs and restart the Docker image.
  73. .. code:: sh
  74. $ docker container restart 2f998
  75. Use command ``container ls`` to list running containers, add flag `-a
  76. <https://docs.docker.com/engine/reference/commandline/container_ls>`__ to list
  77. exited containers also. With ``container stop`` a running container can be
  78. stoped. To get rid of a container use ``container rm``:
  79. .. code:: sh
  80. $ docker container ls
  81. CONTAINER ID IMAGE COMMAND CREATED ...
  82. 2f998d725993 searxng/searxng "/sbin/tini -- /usr/…" 7 minutes ago ...
  83. $ docker container stop 2f998
  84. $ docker container rm 2f998
  85. .. sidebar:: Warning
  86. This might remove all docker items, not only those from SearXNG.
  87. If you won't use docker anymore and want to get rid of all conatiners & images
  88. use the following *prune* command:
  89. .. code:: sh
  90. $ docker stop $(docker ps -aq) # stop all containers
  91. $ docker system prune # make some housekeeping
  92. $ docker rmi -f $(docker images -q) # drop all images
  93. shell inside container
  94. ----------------------
  95. .. sidebar:: Bashism
  96. - `A tale of two shells: bash or dash <https://lwn.net/Articles/343924/>`_
  97. - `How to make bash scripts work in dash <http://mywiki.wooledge.org/Bashism>`_
  98. - `Checking for Bashisms <https://dev.to/bowmanjd/writing-bash-scripts-that-are-not-only-bash-checking-for-bashisms-and-testing-with-dash-1bli>`_
  99. Like in many other distributions, Alpine's `/bin/sh
  100. <https://wiki.ubuntu.com/DashAsBinSh>`__ is :man:`dash`. Dash is meant to be
  101. `POSIX-compliant <https://pubs.opengroup.org/onlinepubs/9699919799>`__.
  102. Compared to debian, in the Alpine image :man:`bash` is not installed. The
  103. :origin:`dockerfiles/docker-entrypoint.sh` script is checked *against dash*
  104. (``make tests.shell``).
  105. To open a shell inside the container:
  106. .. code:: sh
  107. $ docker exec -it 2f998 sh
  108. Build the image
  109. ===============
  110. It's also possible to build SearXNG from the embedded :origin:`Dockerfile`::
  111. $ git clone https://github.com/searxng/searxng.git
  112. $ cd searxng
  113. $ make docker.build
  114. ...
  115. Successfully built 49586c016434
  116. Successfully tagged searxng/searxng:latest
  117. Successfully tagged searxng/searxng:1.0.0-209-9c823800-dirty
  118. $ docker images
  119. REPOSITORY TAG IMAGE ID CREATED SIZE
  120. searxng/searxng 1.0.0-209-9c823800-dirty 49586c016434 13 minutes ago 308MB
  121. searxng/searxng latest 49586c016434 13 minutes ago 308MB
  122. alpine 3.13 6dbb9cc54074 3 weeks ago 5.61MB
  123. Command line
  124. ============
  125. .. sidebar:: docker run
  126. Use flags ``-it`` for `interactive processes
  127. <https://docs.docker.com/engine/reference/run/#foreground>`__.
  128. In the :origin:`Dockerfile` the ENTRYPOINT_ is defined as
  129. :origin:`dockerfiles/docker-entrypoint.sh`
  130. .. code:: sh
  131. docker run --rm -it searxng/searxng -h
  132. .. program-output:: ../dockerfiles/docker-entrypoint.sh -h