hardware / mailserver

:warning: UNMAINTAINED - Simple and full-featured mail server using Docker
https://store.docker.com/community/images/hardware/mailserver
MIT License
1.29k stars 322 forks source link

Postfixadmin can't reach MariaDB #309

Closed elielam closed 6 years ago

elielam commented 6 years ago

Classification

Reproducibility

Docker information

$ docker info

Containers: 23
 Running: 23
 Paused: 0
 Stopped: 0
Images: 23
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-34-generic
Operating System: Ubuntu 18.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 31.28GiB
Name: services
ID: ZAET:O7R4:XJB5:6YCM:D4KF:MMZR:NM7D:LY43:WAGK:4XIR:X64U:AZ5K
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Portainer network view

01ekjcj

$ docker inspect network utilities_network

},
        "ConfigOnly": false,
        "Containers": {

             ...

            "2b01fa919d62accf9250340434404bede9da5cbd0cff600142487be4450e2507": {
                "Name": "mailserver",
                "EndpointID": "bdf25bd3f984779ac80a4952ab109c924ae0fada45e359d8e53c6cd829cc46be",
                "MacAddress": "02:42:ac:13:00:04",
                "IPv4Address": "172.19.0.4/16",
                "IPv6Address": ""
            },
            "85d36fca66abf861ee040c5c5d50ba6b0ee82ed128ef0dc3664b094b77d865e5": {
                "Name": "postfixadmin",
                "EndpointID": "4ea61b9a3eb58e3653d25b339475f8f2ebbb40c4e1a3c69015a566201ea6fcec",
                "MacAddress": "02:42:ac:13:00:07",
                "IPv4Address": "172.19.0.7/16",
                "IPv6Address": ""
            },
            "9dab119cd897b71caf1944e6fb6a536ac6ad33c5ac9ec800e683644c377b81fb": {
                "Name": "rainloop",
                "EndpointID": "f4b59d9ffcb54532996e92f180f428c77481956ac5129f4f009a6bc698e97388",
                "MacAddress": "02:42:ac:13:00:06",
                "IPv4Address": "172.19.0.6/16",
                "IPv6Address": ""
            },
            "b730ff5eee3c3b4f1d0d41f7a44c4dc50388357a9587085c151f8738475551db": {
                "Name": "traefik",
                "EndpointID": "73825e788dc3bc8d782a8e016f3acff513417e540ce9edb0483c96077432b5bf",
                "MacAddress": "02:42:ac:13:00:02",
                "IPv4Address": "172.19.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }

$ docker inspect network utilities_mail_network

},
        "ConfigOnly": false,
        "Containers": {
            "2b01fa919d62accf9250340434404bede9da5cbd0cff600142487be4450e2507": {
                "Name": "mailserver",
                "EndpointID": "2aa2a27b286575391902c82552f7726d0338c64a7e963190220f551e79cb2b56",
                "MacAddress": "02:42:ac:17:00:04",
                "IPv4Address": "172.23.0.4/16",
                "IPv6Address": ""
            },
            "85d36fca66abf861ee040c5c5d50ba6b0ee82ed128ef0dc3664b094b77d865e5": {
                "Name": "postfixadmin",
                "EndpointID": "3964b18db8794bcd640ede1e3ba4b9f2b8ac0fd2d5550c9979d6edba84354390",
                "MacAddress": "02:42:ac:17:00:05",
                "IPv4Address": "172.23.0.5/16",
                "IPv6Address": ""
            },
            "9668f8bf887cdcf10fe51e441553c2d5f84f9fbd27a27a2f24e0bc13b2f43184": {
                "Name": "mail_mariadb",
                "EndpointID": "cbe5785282e283d732be88dd997f5d18f26fa9a2b5f9de27bf25573d2a85162e",
                "MacAddress": "02:42:ac:17:00:02",
                "IPv4Address": "172.23.0.2/16",
                "IPv6Address": ""
            },
            "9dab119cd897b71caf1944e6fb6a536ac6ad33c5ac9ec800e683644c377b81fb": {
                "Name": "rainloop",
                "EndpointID": "1c10738315434f0055b250007eda62fc8d30b7c9846cba9cdc436a9c5063fd13",
                "MacAddress": "02:42:ac:17:00:06",
                "IPv4Address": "172.23.0.6/16",
                "IPv6Address": ""
            },
            "f3a7d2999dc597e178ba6855abad0fc159d303303cf0c5ec7b3f9181535af177": {
                "Name": "mail_redis",
                "EndpointID": "7f1925ba3e0abfba045d0082ae932872646ba5c240b3853d2fc916681d5b065b",
                "MacAddress": "02:42:ac:17:00:03",
                "IPv4Address": "172.23.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }

The network db_network serves me to access my different databases via adminer.

Description

I am currently experiencing a problem with the configuration of Postfix and Mariadb. Even after modifying the config.inc.php file postfix seems not be able to reach db.

akdnijd

docker-compose.yml mariadb conf

      - MYSQL_DATABASE=postfix
      - MYSQL_USER=postfix
      - MYSQL_PASSWORD="password"

config.inc.php

$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = '172.23.0.2';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'password';
$CONF['database_name'] = 'postfix';

Debugging information

rtragxs

Postfix Web server seems not have any trouble

30x477t

Configuration (docker-compose.yml, traefik.toml...etc)

docker-compose.yml

...
mailserver:
    image: hardware/mailserver:1.1-stable
    container_name: mailserver
    restart: always
    depends_on:
      - mail_mariadb
      - mail_redis
    extra_hosts:
      - "mariadb:172.23.0.2"
      - "redis:172.23.0.3"                   
    domainname: ${SERVER_DOMAIN}
    hostname: mail
    networks:
      - utilities_network
      - mail_network
    ports:
      - "25:25"       # SMTP                - Required
      - "143:143"     # IMAP       STARTTLS - Optional - For webmails/desktop clients
      - "587:587"    # Submission STARTTLS - Optional - For webmails/desktop clients
      - "993:993"     # IMAPS      SSL/TLS  - Optional - For webmails/desktop clients
      - "4190:4190"   # SIEVE      STARTTLS - Optional - Recommended for mail filtering
    volumes:
      - /srv/appdata/utilities/mail:/var/mail
    environment:
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
      - DBPASS=${MAIL_DB_PASSWORD}
      - RSPAMD_PASSWORD=${MAIL_MONITORING_PASSWORD}
    labels:
      - traefik.enable=true
      - traefik.frontend.rule=Host:monitoring.mail.${SERVER_DOMAIN}
      - traefik.port=11334
      - traefik.docker.network=utilities_network
      - traefik.backend=Mail

  postfixadmin:
    image: hardware/postfixadmin
    container_name: postfixadmin
    restart: always
    depends_on:
      - mailserver
      - mail_mariadb
    networks:
      - utilities_network
      - mail_network
    domainname: ${SERVER_DOMAIN}
    hostname: mail
    environment:
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
      - DBPASS="password"
    labels:
      - traefik.enable=true
      - traefik.frontend.rule=Host:dashboard.mail.${SERVER_DOMAIN}
      - traefik.port=8888
      - traefik.docker.network=utilities_network
      - traefik.backend=Postfixadmin

  rainloop:
    image: hardware/rainloop
    container_name: rainloop
    restart: always
    depends_on:
      - mailserver
      - mail_mariadb
    networks:
      - utilities_network
      - mail_network
    environment:
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
    volumes:
      - /srv/appdata/utilities/mail/rainloop:/rainloop/data
    labels:
      - traefik.enable=true
      - traefik.port=8888
      - traefik.frontend.rule=Host:web.mail.${SERVER_DOMAIN}
      - traefik.docker.network=utilities_network
      - traefik.backend=Rainloop

  mail_mariadb:
    image: mariadb:10.2
    container_name: mail_mariadb
    restart: always
    networks:
      - mail_network
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
      - MYSQL_DATABASE=postfix
      - MYSQL_USER=postfix
      - MYSQL_PASSWORD="password"
    volumes:
      - /srv/appdata/utilities/mail/mysql/db:/var/lib/mysql
    labels:
      - traefik.enable=false

  mail_redis:
    image: redis:4.0-alpine
    container_name: mail_redis
    restart: always
    command: redis-server --appendonly yes
    networks:
      - mail_network    
    environment:
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
    volumes:
      - /srv/appdata/utilities/mail/redis/db:/data
    labels:
      - traefik.enable=false

...

networks:
  mail_network:
    external: false
  utilities_network:
    external:
      name: utilities_network
  db_network:
    external:
      name: db_network

Sorry for my bad english you can reply in french if you want. thank you in advance.

navossoc commented 6 years ago

Try to set DBHOST in postfixadmin service as mail_mariadb

  postfixadmin:
    image: hardware/postfixadmin
    container_name: postfixadmin
    restart: always
    depends_on:
      - mailserver
      - mail_mariadb
    networks:
      - utilities_network
      - mail_network
    domainname: ${SERVER_DOMAIN}
    hostname: mail
    environment:
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
      - DBPASS="password"
      - DBHOST=mail_mariadb
    labels:
      - traefik.enable=true
      - traefik.frontend.rule=Host:dashboard.mail.${SERVER_DOMAIN}
      - traefik.port=8888
      - traefik.docker.network=utilities_network
      - traefik.backend=Postfixadmin

You can check it here: https://github.com/hardware/postfixadmin/blob/920d734fca0b8e8603cef1972106d61f00f04b4c/bin/run.sh#L45-L50

elielam commented 6 years ago

Ok ty, you were right the link between postfix and db is now established.

Now the message had change:

ehztaur

I had already deal with this error but i don't remember how i fix it ..

elielam commented 6 years ago

I've found this ticket, but don't understand what was the problem.

https://github.com/hardware/postfixadmin/issues/15

navossoc commented 6 years ago

You should also sync the configs on the mail_mariadb service with the postfixadmin

  mail_mariadb:
    # ...
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
      - MYSQL_DATABASE=postfix
      - MYSQL_USER=postfix
      - MYSQL_PASSWORD=password
  postfixadmin:
    # ...
    environment:
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
      - DBPASS="password"

The default database and user are called postfix, have you changed it? If so, you may need to set DBUSER and DBNAME on postfixadmin service.

Another problem could be that quotation marks that you are using on the password, may I suggest a simpler password for tests? (without the quotes or special characters) as it may being bad interpreted by docker (you may need to escape some character).

elielam commented 6 years ago

All information describe in docker-compose are right for mail_mariadb i can connect to mysql with user

postfix

and pass

password

and i found the postfix db

bndzy29

When i reach mariadb from postfixadmin

ehztaur

I removed DBUSER and DBNAME variables in docker-compose file because after mount docker container it seem not take this variables in count.

navossoc commented 6 years ago

Try to get the content of the /postfixadmin/config.local.php

docker exec postfixadmin cat /postfixadmin/config.local.php

It may help, maybe something is being set wrong there...

Take a closer look at the $CONF['database_...'] variables.

--

Can you USE postfix database and select it content? (have you permissions to use it, are postfix the owner?)

elielam commented 6 years ago

You were right thank you very much.

I add DBUSER and DBNAME variables to docker-compose.yml and it's work fine here it's my sample I don't either need to manually change config.inc.php file anymore.

postfixadmin:
    image: hardware/postfixadmin
    container_name: postfixadmin
    restart: always
    depends_on:
      - mailserver
      - mail_mariadb
    networks:
      - utilities_network
      - mail_network
    domainname: ${SERVER_DOMAIN}
    hostname: mail
    environment:
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
      - DBPASS=password
      - DBHOST=mail_mariadb
      - DBUSER=postfix
      - DBNAME=postfix
    labels:
      - traefik.enable=true
      - traefik.frontend.rule=Host:dashboard.mail.${SERVER_DOMAIN}
      - traefik.port=8888
      - traefik.docker.network=utilities_network
      - traefik.backend=Postfixadmin

 ...

 mail_mariadb:
    image: mariadb:10.2
    container_name: mail_mariadb
    restart: always
    networks:
      - mail_network
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
      - PUID=${USERID}
      - PGID=${GROUPID}
      - TZ=${TIMEZONE}
      - MYSQL_DATABASE=postfix
      - MYSQL_USER=postfix
      - MYSQL_PASSWORD=password
    volumes:
      - /srv/appdata/utilities/mail/mysql/db:/var/lib/mysql
    labels:
      - traefik.enable=false

Ty again for your time.

navossoc commented 6 years ago

I don't either need to manually change config.inc.php file anymore.

You shouldn't do that, it will only bring you problems.

I think you are new using docker right? I'm no expert either, but you may take a read about how the data are persisted on it. You will see that the files inside the container are lost each time the container is (re)created.

If you want to persist some kind of data/changes you will need a bind mount ou a volume mount.

Ty again for your time.

No problem, glad to help 😃

[]'s

elielam commented 6 years ago

Yes I discover docker by the installation of my server.

I understand, especially with the use of docker-compose that it is not good to modify files manually after mounting the container.

I will read more about it thanks.