Persistent local SearX

Hi, I follow the manual here : Docker installation — Searx Documentation (Searx-1.0.0.tex)

I put the local searx as default.

Everything is ok, untill I restart my Manjaro : then, I see docker is running, the searX container exists but I cannot open it anymore on localhost:80

Anyone with experience on this ?

1 Like

I run a searx instance on a raspberry pi using minimal Raspian :slight_smile:

I checked the docker type install and it works as described at Docker installation — Searx Documentation (Searx-1.0.0.tex)

[tiger fh]# docker pull searx/searx
Using default tag: latest
latest: Pulling from searx/searx
3d2430473443: Pull complete 
c30eb5f0c6f4: Pull complete 
26b44ef74329: Pull complete 
e0fbc63b49d3: Pull complete 
7bfb52d56755: Pull complete 
7187505f56e9: Pull complete 
7c829c3bc002: Pull complete 
Digest: sha256:71aa82216e1cdaffc6c5605221cbc7f7ff746369a480620c8ff87ea4b0c0df19
Status: Downloaded newer image for searx/searx:latest
docker.io/searx/searx:latest
[tiger fh]# export PORT=80
[tiger fh]# docker run --rm -d -v ${PWD}/searx:/etc/searx -p $PORT:8080 -e BASE_URL=http://localhost:$PORT/ searx/searx
289e35328167ff3cc2f5b4d50ef0a09b7003bf9d83206014499c6daed944e8cf

Yes, by me it does work as well… untill reboot :confused:

Do you imply I should change the ports during first install ?

After a reboot you need to start the container.

What is the output of docker ps after the reboot. Is the container really running?

~]$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[me@ordi ~]$

I see that --rm removes the container if stopped.

Should I change this of create a script with

export PORT=80
docker run --rm -d -v ${PWD}/searx:/etc/searx -p $PORT:8080 -e BASE_URL=http://localhost:$PORT/ searx/searx

to be run at startup ?

Even if you don’t remove the container after it stops, you need to start the container after a reboot.

I would create a systemd services that starts and stops the container. It can even pull a new version at startup if necessary.

How do you do this ?

I’m totally newbie on containers (and never was a service specialist) :slight_smile:

I would use something like this

[Unit]
Description=searx container
After=network-online.target
Requires=network.target 

[Service]
TimeoutStartSec=0
TimeoutStopSec=30
User=xabbu
ExecStartPre=-/usr/bin/docker kill searx
ExecStartPre=-/usr/bin/docker rm searx
ExecStartPre=-/usr/bin/docker pull searx/searx
ExecStart=/usr/bin/docker run \
    --name searx \
    -v /home/xabbu/searx:/etc/searx \
    -p 80:8080 \
    -e BASE_URL=http://localhost:80/ \
    searx/searx
ExecStop=/usr/bin/docker kill searx
ExecStopPost=-/usr/bin/docker rm searx
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

You want at least change the username and the path for the mount. The commands that start with - can fail. The first two ExecStartPre commands are not necessary, but sometimes it is better to play save.

1 Like

Wahh !
Seems to work perfectly.

I had to make it as root :

su -
systemctl edit --force --full searx.service

And copy/paste your suggestion (with my username)

I have polishing questions:

  • Why do you put a - after the ExecStartPre= ?
  • How do I check that the other commands with a minus sign actually work ?
  • I can launch searx with http://localhost/search instead of http://localhost:80 but have no idea of why !

The - indicates that the command is allowed to fail (it fails if there is no searx container to kill or remove.
You don’t, the - ignores errors. However, if they fail, the Start one would complain.

Because http by default is using port 80.

A small suggestions from my side is to change the port forwarding to “127.0.0.1:80:8080” so that you’re not globally opening up port 80 for everyone (in you network) to use. (Except you want that, of course.)

Also, wouldn’t a --restart always be quicker instead of this long service? And why killing the container?

2 Likes

Well, thank you all : I learn a lot on this thread :slight_smile:

I do have a last issue : somehow I cannot keep the preferences I set up in SearX

It tells me it is reachable @ http://localhost/?preferences=VeryLongAlphaNumericString&q=%s

But this adresse leads to nothing and If I close my browser instances and reopen, I’m on a fresh profile.

What do I miss ?

Would --restart always survive a reboot?

It is just to stop the container before the system shuts down. The docker stop did not always worked reliable. But I must admit, I tested this a very log time ago.

Yes, that’s the point of having it.

So, I did:

systemctl stop searx
systemctl disable searx
docker container stop strange_name
docker run --restart=always -d -v ${PWD}/searx:/etc/searx -p 80:8080 -e BASE_URL=http://localhost:80/ searx/searx

(replacing --rm with --restart=always )

Restarted and it works.

Shutdown was a little longer.
I still didn’t find out how to keep the settings (don’t have them @ reboot)

Which settings are you talking about? You mount the /etc/searx folder of the container, I guess the settings are stored there.

Above, you were talking about the browser, I don’t know how it’s store but it’ll be with cookies. That depends on your browser settings.

Edit: I have just tested it, and it works :person_shrugging:

1 Like

:sweat_smile: Got it ! I’ll have to amend the setting file : here I amended in the browser where I do use site bleacher that… cleans the cookies !

How do you do this ?


Another idea here, by the way : would this be a multidevice solution for personal or family use ?

It is recommended to read the Arch Wiki on docker

A user service executing a script would suffice - after all it is only for your usage - right?

user docker script

Create a script in ~/.local/bin name it searx.sh and make it executable

mkdir -p ~/.local/bin
touch ~/.local/bin/searx.sh

Edit the file and paste below content

#!/usr/bin/env bash

if [[ $1 == 'stop' ]]; then
    docker kill $(docker container ls | grep 'searx/searx' | cut -d' ' -f1)
    exit 0
fi
# set a work dir
workdir=/tmp/$USER
export PORT=80
docker pull searx/searx
docker run --rm -d -v ${workdir}/searx:/etc/searx -p $PORT:8080 -e BASE_URL=http://localhost:$PORT/ searx/searx

user setup

Add your username to docker group (remember to log-off and login to activate the group)

sudo gpasswd -a $USER docker

user service unit

Create a local .config/systemd/user folder and create the service file

mkdir -p ~/.config/systemd/user
touch ~/.config/systemd/user/searx.service

Edit the service file and paste below content

[Unit]
Description=Local Searx search engine

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/home/%u/.local/bin/searx.sh
ExecStop=/home/%u/.local/bin/searx.sh

[Install]
WantedBy=default.target

Enable the the user service

systemctl --user enable --now 

Unit files need the absolute path: /usr/bin/bash.

You already do with the -v option.

Here, I would recommend setting a good path instead of relying on PWD. I wouldn’t know where the current working directory is for such a unit:
${HOME}/.config/searx:/etc/searx

Yes - you are right - I didn’t think of that - it all depends on where you are when you launch the service.

I will experiment with this :slight_smile:

Reworked the setup - setting a path as you noted.

Well, I’m puzzled now ! :melting_face:

Do I stay with the --restart=always or do I restart a service (What does minimize process & RAM consumption ?

Where do I find the /etc/searx folder ?