Cannot connect to Airnotifier docker container from Moodle container

Cannot connect to Airnotifier docker container from Moodle container

by Govindaprasath E -
Number of replies: 3
I am running Moodle and Airnotifier containers locally using docker compose.

Docker yaml for Moodle 4.0.0:

version: '3.4'
services:
  mariadb:
    image: mariadb
    container_name: mariadb
    restart: always
    volumes:
      - ./Configs/Databases/Moodle:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=moodle
      - MYSQL_ROOT_USER=root
      - MYSQL_DATABASE=moodle

  moodle:
    image: bitnami/moodle:4.0
    container_name: moodle400
    restart: always
    ports:
      - 8080:8080
      - 8443:8443
    environment:
      - MOODLE_DATABASE_HOST=mariadb
      - MOODLE_DATABASE_USER=root
      - MOODLE_DATABASE_PASSWORD=moodle
      - MOODLE_DATABASE_NAME=moodle
      - PUID=998
      - PGID=100
    volumes:
      - ./Configs/Moodle:/bitnami/moodle
      - ./Configs/MoodleData:/bitnami/moodledata
    depends_on:
      - mariadb
    links:
      - mariadb:mariadb


I cloned https://github.com/dcai/airnotifier and run using the yaml file:

# After staring container, don't forget to install db :
#   docker exec -it airnotifier python /airnotifier/install.py

version: "3"
services:
  mongodb:
    image: mongo:3.4
    container_name: mongodb
    restart: always
    ports:
      - 27017:27017
    environment:
      - MONGO_DATA_DIR=/data/db
      - MONGO_LOG_DIR=/tmp/mongo/mongo.log
    volumes:
      - ./mongo/data:/data/db
      - ./mongo/log:/tmp/mongo
    command: mongod --logpath=/dev/null # --quiet
  airnotifier:
    links:
      - mongodb
    depends_on:
      - mongodb
    build: .
    container_name: airnotifier
    restart: always
    volumes:
      - .:/airnotifier
      - ./certs:/var/airnotifier/pemdir
      - ./logs:/var/log/airnotifier
    ports:
      - 8801:8801
    environment:
      - MONGO_SERVER=mongodb
      - MONGO_PORT=27017

The two containers created its own network in bridge mode and they are accessible from my browser as localhost.Then I logged into Moodle as admin and set airnotifier settings as:
Airnotifier
 
But when I Click "Check and test push notification configuration", I get the error:
This site is not able to connect to the notifications server http://localhost:8801

Then I change all the containers to the same network using:
docker network connect moodledockerdbtech_default airnotifier
docker network connect moodledockerdbtech_default mongodb

When I run docker network inspect moodledockerdbtech_default :

[
    {
        "Name": "moodledockerdbtech_default",
        "Id": "f9244d2e21ac0a721d2eb25ab1604b2332f39ba693613c0ec65557ca58167bb9",
        "Created": "2023-08-20T10:32:43.523379034+05:30",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "94f66fabd90cdb079fbf5802df8ecadb01d2d6e9f22addf8f5f2c4862227c5cf": {
                "Name": "mariadb",
                "EndpointID": "7321374b55dcc396f901edb9e3ac4e25190d394062c584c8d226c023474dd710",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "bb2056f612d88e58caad2fb98b286ea0eef5e33e71d9ee7b5d6c60a2a70e7962": {
                "Name": "mongodb",
                "EndpointID": "7ab30a4551120fa8cbf90b214278abb7c67965a2d6d658b78058a6e6bc5d25d5",
                "MacAddress": "02:42:ac:12:00:05",
                "IPv4Address": "172.18.0.5/16",
                "IPv6Address": ""
            },
            "e0e1bba876c61698f697d40657f26358c2844937cbc44f36247fbb0b7a16d7c1": {
                "Name": "airnotifier",
                "EndpointID": "b528d1222e6f46e884490385dcaad6812067689337f5583a034957daec77e58b",
                "MacAddress": "02:42:ac:12:00:04",
                "IPv4Address": "172.18.0.4/16",
                "IPv6Address": ""
            },
            "fc05bf502b027cbf29ce5abb53bc0df0002cf5644f7e421131afb3887520358a": {
                "Name": "moodle400",
                "EndpointID": "8832c7be2590dfec0338236e1a317ee753508b4718c535fc6cae37671df6bd16",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "moodledockerdbtech",
            "com.docker.compose.version": "2.20.2"
        }
    }
]

Then I change the Airnotifier URL in the Moodle administrator setting as 172.18.0.4 I still get:
This site is not able to connect to the notifications server http://172.18.0.4:8801

How can I connect the moodle server to the airnotifier server?
Average of ratings: -
In reply to Govindaprasath E

Re: Cannot connect to Airnotifier docker container from Moodle container

by Govindaprasath E -
I was never able to solve this, so had to resort to hosting Airnotifier in the AWS server.
In reply to Govindaprasath E

Re: Cannot connect to Airnotifier docker container from Moodle container

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I missed your original post. Pointing moodle to http://localhost:8100 definitely won't work, because that's trying to connect to port 8100 on the moodle container, rather than the airnotifier one. Have you tried http://airnotifier for the airnotifierurl setting? Containers in the same docker network should be able to find each other by hostname.

In reply to Mark Johnson

Re: Cannot connect to Airnotifier docker container from Moodle container

by Govindaprasath E -
Thanks for you input Mark.
Since I posted this, I moved to a Macbook pro and I am running a Ubuntu 18 Server in my Mac using UTM. In this server I have installed AIrnotifier and I am able to login it it using: http://192.168.64.3:8801/. I also set "https=False" in the config.py before installing airnotifier.
Then I setup a local instance of Moodle using Moodle MAMP and setup the local server using: https://docs.moodle.org/404/en/Installation_Package_for_macOS
In mobile notification settings page at the server I have entered:
Airnotifier URL: http://192.168.64.3
Airnotifier Port: 8801
So this is solved now, I am able to run Airnotifier locally in my computer and get push notification in my mobile app, when I click them I am being taken to the app home page.
Now the only problem I need to solve is how I can make these push notifications open their respective screen in the mobile app.
Average of ratings:Useful (1)