mediagis / nominatim-docker

100% working container for Nominatim
Creative Commons Zero v1.0 Universal
1.09k stars 444 forks source link

Error on M1 Mac: Apache start failed #505

Closed JochenFromm closed 5 months ago

JochenFromm commented 10 months ago

Describe the bug

The latest Docker image 4.3 can not be started completely on an M1 Mac because the Apache server won't start. It looks like this is caused by problems related to the M1 Max chip.

The older Docker image from Peter Evans works https://github.com/peter-evans/nominatim-docker

To Reproduce

Steps to reproduce the behavior:

Running the older Docker image from Peter Evans works as expected without problems:

$ docker run -d -p 9000:8080 \
  -e NOMINATIM_PBF_URL=http://download.geofabrik.de/asia/maldives-latest.osm.pbf \
  --name nominatim \
  peterevans/nominatim:latest
> <CONTAINER ID>
$ docker logs -f <CONTAINER ID>
...wait until started...
$ curl "localhost:9000/search.php?q=Baros&format=json" 
[{"place_id":106254,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"way","osm_id":116704220,"boundingbox":["4.2834742","4.2859758","73.4259013","73.4282571"],"lat":"4.284732399999999","lon":"73.42723848863355","display_name":"Baros, މާލެ އަތޮޅު, Maldives","class":"place","type":"islet","importance":0.36}]

But when I am trying to run the Mediagis 4.3 Docker image on an M1 Mac (arch shows "i386" as architecture)...

$ arch
i386
$ docker run -it \
  -e PBF_URL=http://download.geofabrik.de/asia/maldives-latest.osm.pbf \
  -p 9000:8080 \
  --name nominatim \
  mediagis/nominatim:4.3

...I get the error that Apache can not be started. Even adding the parameter --platform linux/amd64 to the Docker run call does not help

Expected behavior

Docker containing including Apache instance can be started successfully

Screenshots & Logs

The logs show the following error

+ service apache2 start
 * Starting Apache httpd web server apache2 
[Sun Nov 19 12:35:19.131980 2023] [core:emerg] [pid 1161] 
(95)Operation not supported: AH00023: Couldn't create the mpm-accept mutex 
(95)Operation not supported: could not create accept mutex
AH00015: Unable to open logs
Action 'start' failed.

Desktop / Server

Additional context

Apache can be started if we log into the Docker container while it is still running, add a line to the Apache config and restart the Apache server, as described here

docker exec -it -u 0 nominatim /bin/bash
echo "Mutex posixsem" >> /etc/apache2/apache2.conf
./startapache.sh
leonardehrenfried commented 10 months ago

Are there any consequences for non-arm users if we added this line to the Apache config?

JochenFromm commented 10 months ago

I am not sure 😕 As you know a mutex is a mutual exclusion lock to prevent race conditions and to control access to shared resources and critical sections. In the worst case changing the mutex setting can lead to a web server that hangs or crashes. The Apache documentation says that posixsem as mutex setting is not available on all platforms.

Maybe it helps to specify the right platform in the build process itself 🤔

docker build --platform=linux/amd64 -t nominatim .
JochenFromm commented 10 months ago

Specifying the platform for docker build does not help to solve the problem either 😞 Does anyone know a better solution than adding Mutex posixsem to the Apache configuration?

philipkozeny commented 10 months ago

@JochenFromm

➜  ~ arch
arm64

That's the result I get running arch on my M1 Pro. Anything specific you have changed to get i386 instead of arm64 as a result?

JochenFromm commented 10 months ago

Yes, I have checked "Open using Rosetta" in the settings of /System/Applications/Utilities/Terminal.app to get old legacy applications and older software running.

Does it work if arch shows arm64 ? Then this would be a solution.

philipkozeny commented 10 months ago

Yes, I have checked "Open using Rosetta" in the settings of /System/Applications/Utilities/Terminal.app to get old legacy applications and older software running.

Does it work if arch shows arm64 ? Then this would be a solution.

Yes, it does work.

==> /var/log/apache2/access.log <==
192.168.65.1 - - [20/Nov/2023:10:55:47 +0000] "GET / HTTP/1.1" 200 231 "-" "curl/8.1.2"
JochenFromm commented 10 months ago

Somehow it does not work for me, even if arch shows arm64. Here is the log which still shows "Action 'start' failed" for Apache https://gist.github.com/JochenFromm/3a1ccb57279a2deaf8b312937735a44e

JochenFromm commented 10 months ago

I tried everything, including updating Docker Desktop Version: 4.9.1 to 4.25.1 and using arm64 instead of i386.

Apache refuses to start on my M1 Macbook unless the Mutex is set. Mutex flock and Mutex file also work, as this Stackoverflow page says. The only way I get the Apache webserver running is to add Mutex posixsem,Mutex flock or Mutex file to /etc/apache2/apache2.conf

Mutex posixsem|flock|file

Alternatively it is also possible to add it this setting to the file as suggest in this page says

/etc/apache2/conf-available/mutex.conf
JochenFromm commented 10 months ago

I get it to work if I use the older version mediagis/nominatim:4.0. Then it works for i368 and arm64 on my M1 Max Macbook. Logging into the Docker container gives the following versions for 4.0:

$ docker exec -it nominatim bash 
# php --version 
PHP 7.4.3 (cli) (built: Nov  2 2022 09:53:44) ( NTS )
# apache2 -v
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2022-06-14T13:30:55

These are the same versions as in the Docker image peterevans/nominatim:latest which works too.

The latest Docker mediagis/nominatim:4.3 has PHP Version 8.1.2 and Apache Version 2.4.52. Since Apache is the problem because it refuses to start most likely something in the version 2.4.52 has changed that causes it to fail, compared to version 2.4.41 which worked.

If someone has the same problem for the image mediagis/nominatim:4.3 then using the older image mediagis/nominatim:4.0 should help to fix it as a workaround:

docker run -it \
  -e PBF_URL=http://download.geofabrik.de/asia/maldives-latest.osm.pbf \
  -p 9000:8080 \
  --name nominatim \
  mediagis/nominatim:4.0
philipkozeny commented 5 months ago

I am going to close that issue since it's not reproducible on our side with a fresh install of Macs with M processors, feel free to reopen it if it happens again.