installation-docker.rst 5.6 KB

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