mainflux: Containers can't connect: Failed to connect to postgres

Hello, I use Windows-> virtualbox+ubuntuserver (22.04.1) + docker(20.10.17) + docker-compose(1.29.2) -> trying to run mainflux

Do steps:

git clone [https://github.com/mainflux/mainflux.git](https://github.com/mainflux/mainflux)
cd mainflux
sudo make run

And then Mainflux running, and fisrt error - mainflux-auth trying to connect to postgres and failed, then same error: mainflux-coap trying to connect to broker and failed, etc And I don’t understand how to fix this. Why they can’t connect to each other? I check: are all of containers stay in one net - yes, all of them in docker_mainflux-base-net

napster@salmon:~/mainflux$ sudo make run
sed -i "s,file: brokers/.*.yml,file: brokers/nats.yml," docker/docker-compose.ym                                          l
sed -i "s,MF_BROKER_URL: .*,MF_BROKER_URL: $\{MF_NATS_URL\}," docker/docker-comp                                          ose.yml
docker-compose -f docker/docker-compose.yml up
mainflux-auth-redis is up-to-date
mainflux-auth-db is up-to-date
mainflux-users-db is up-to-date
mainflux-keto-db is up-to-date
mainflux-es-redis is up-to-date
mainflux-things-db is up-to-date
mainflux-jaeger is up-to-date
mainflux-broker is up-to-date
mainflux-vernemq is up-to-date
mainflux-keto is up-to-date
mainflux-keto-migrate is up-to-date
mainflux-auth is up-to-date
mainflux-things is up-to-date
mainflux-users is up-to-date
mainflux-mqtt is up-to-date
mainflux-coap is up-to-date
mainflux-http is up-to-date
mainflux-nginx is up-to-date
Attaching to mainflux-auth-redis, mainflux-auth-db, mainflux-users-db, mainflux-keto-db, mainflux-es-redis, mainflux-things-db, mainflux-jaeger, mainflux-broker, mainflux-vernemq, mainflux-keto, mainflux-keto-migrate, mainflux-auth, mainflux-things, mainflux-users, mainflux-mqtt, mainflux-coap, mainflux-http, mainflux-nginx
mainflux-auth   | {"level":"error","message":"Failed to connect to postgres: dial tcp 172.18.0.6:5432: connect: connection timed out","ts":"2022-08-23T07:58:57.483351911Z"}
mainflux-auth   | {"level":"error","message":"Failed to connect to postgres: dial tcp 172.18.0.6:5432: connect: connection timed out","ts":"2022-08-23T08:01:10.600678469Z"}
mainflux-auth   | {"level":"error","message":"Failed to connect to postgres: dial tcp 172.18.0.6:5432: connect: connection timed out","ts":"2022-08-23T08:03:23.721269587Z"}
mainflux-auth   | {"level":"error","message":"Failed to connect to postgres: dial tcp 172.18.0.6:5432: connect: connection timed out","ts":"2022-08-24T10:52:37.601279534Z"}
mainflux-auth   | {"level":"error","message":"Failed to connect to postgres: dial tcp 172.18.0.6:5432: connect: connection timed out","ts":"2022-08-24T10:54:50.72456827Z"}
mainflux-auth-redis | 1:C 23 Aug 2022 07:56:21.373 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
mainflux-auth-redis | 1:C 23 Aug 2022 07:56:21.397 # Redis version=6.2.2, bits=64, commit=00000000, modified=0, pid=1, just started
mainflux-auth-redis | 1:C 23 Aug 2022 07:56:21.397 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
mainflux-auth-redis | 1:M 23 Aug 2022 07:56:21.398 * monotonic clock: POSIX clock_gettime
mainflux-auth-redis | 1:M 23 Aug 2022 07:56:21.406 * Running mode=standalone, port=6379.
mainflux-auth-redis | 1:M 23 Aug 2022 07:56:21.413 # Server initialized
mainflux-auth-redis | 1:M 23 Aug 2022 07:56:21.413 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
mainflux-auth-redis | 1:M 23 Aug 2022 07:56:21.414 * Ready to accept connections
mainflux-auth-db | The files belonging to this database system will be owned by user "postgres".
mainflux-auth-db | This user must also own the server process.
mainflux-auth-db |
mainflux-auth-db | The database cluster will be initialized with locale "en_US.utf8".
mainflux-auth-db | The default database encoding has accordingly been set to "UTF8".
mainflux-auth-db | The default text search configuration will be set to "english".
mainflux-auth-db |
mainflux-auth-db | Data page checksums are disabled.
mainflux-auth-db |
mainflux-auth-db | fixing permissions on existing directory /var/lib/postgresql/data ... ok
mainflux-auth-db | creating subdirectories ... ok
mainflux-auth-db | selecting dynamic shared memory implementation ... posix
mainflux-auth-db | selecting default max_connections ... 100
mainflux-auth-db | selecting default shared_buffers ... 128MB
mainflux-auth-db | selecting default time zone ... UTC
mainflux-auth-db | creating configuration files ... ok
mainflux-auth-db | running bootstrap script ... ok
mainflux-auth-db | sh: locale: not found
mainflux-auth-db | 2022-08-23 07:56:41.922 UTC [31] WARNING:  no usable system locales were found
mainflux-auth-db | performing post-bootstrap initialization ... ok
mainflux-auth-db | initdb: warning: enabling "trust" authentication for local connections
mainflux-auth-db | You can change this by editing pg_hba.conf or using the option -A, or
mainflux-auth-db | --auth-local and --auth-host, the next time you run initdb.
mainflux-auth-db | syncing data to disk ... ok
mainflux-auth-db |
mainflux-auth-db |
mainflux-auth-db | Success. You can now start the database server using:
mainflux-auth-db |
mainflux-auth-db |     pg_ctl -D /var/lib/postgresql/data -l logfile start
mainflux-auth-db |
mainflux-auth-db | waiting for server to start....2022-08-23 07:57:02.665 UTC [36] LOG:  starting PostgreSQL 13.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.3.1_git20210424) 10.3.1 20210424, 64-bit
mainflux-auth-db | 2022-08-23 07:57:02.681 UTC [36] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
mainflux-auth-db | 2022-08-23 07:57:02.764 UTC [37] LOG:  database system was shut down at 2022-08-23 07:56:51 UTC
mainflux-auth-db | 2022-08-23 07:57:02.811 UTC [36] LOG:  database system is ready to accept connections
mainflux-auth-db |  done
mainflux-auth-db | server started
mainflux-auth-db | CREATE DATABASE
mainflux-auth-db |
mainflux-auth-db |
mainflux-auth-db | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
mainflux-auth-db |
mainflux-auth-db | 2022-08-23 07:57:07.161 UTC [36] LOG:  received fast shutdown request
mainflux-auth-db | waiting for server to shut down....2022-08-23 07:57:07.182 UTC [36] LOG:  aborting any active transactions
mainflux-auth-db | 2022-08-23 07:57:07.189 UTC [36] LOG:  background worker "logical replication launcher" (PID 43) exited with exit code 1
mainflux-auth-db | 2022-08-23 07:57:07.203 UTC [38] LOG:  shutting down
mainflux-auth-db | 2022-08-23 07:57:07.452 UTC [36] LOG:  database system is shut down
mainflux-auth-db |  done
mainflux-auth-db | server stopped
mainflux-auth-db |
mainflux-auth-db | PostgreSQL init process complete; ready for start up.
mainflux-auth-db |
mainflux-auth-db | 2022-08-23 07:57:07.639 UTC [1] LOG:  starting PostgreSQL 13.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.3.1_git20210424) 10.3.1 20210424, 64-bit
mainflux-auth-db | 2022-08-23 07:57:07.650 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
mainflux-auth-db | 2022-08-23 07:57:07.650 UTC [1] LOG:  listening on IPv6 address "::", port 5432
mainflux-auth-db | 2022-08-23 07:57:07.685 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
mainflux-auth-db | 2022-08-23 07:57:07.714 UTC [50] LOG:  database system was shut down at 2022-08-23 07:57:07 UTC
mainflux-auth-db | 2022-08-23 07:57:07.747 UTC [1] LOG:  database system is ready to accept connections
mainflux-coap   | 2022/08/23 07:57:12 The binary was build using Nats as the message broker
mainflux-coap   | {"level":"info","message":"gRPC communication is not encrypted","ts":"2022-08-23T07:57:12.189149687Z"}
mainflux-coap   | {"level":"error","message":"Failed to connect to message broker: dial tcp 172.18.0.5:4222: i/o timeout","ts":"2022-08-23T07:57:14.283573538Z"}
mainflux-coap   | 2022/08/23 07:57:18 The binary was build using Nats as the message broker
mainflux-coap   | {"level":"info","message":"gRPC communication is not encrypted","ts":"2022-08-23T07:57:18.56438903Z"}
mainflux-coap   | {"level":"error","message":"Failed to connect to message broker: dial tcp 172.18.0.5:4222: i/o timeout","ts":"2022-08-23T07:57:20.586327157Z"}
mainflux-coap   | 2022/08/23 07:57:24 The binary was build using Nats as the message broker
mainflux-coap   | {"level":"info","message":"gRPC communication is not encrypted","ts":"2022-08-23T07:57:24.339861285Z"}
mainflux-coap   | {"level":"error","message":"Failed to connect to message broker: dial tcp 172.18.0.5:4222: i/o timeout","ts":"2022-08-23T07:57:26.350621388Z"}
mainflux-coap   | 2022/08/23 07:57:30 The binary was build using Nats as the message broker
mainflux-coap   | {"level":"info","message":"gRPC communication is not encrypted","ts":"2022-08-23T07:57:30.231964825Z"}
mainflux-coap   | {"level":"error","message":"Failed to connect to message broker: dial tcp 172.18.0.5:4222: i/o timeout","ts":"2022-08-23T07:57:32.244119421Z"}
mainflux-coap   | {"level":"info","message":"gRPC communication is not encrypted","ts":"2022-08-23T07:57:36.285797597Z"}

...

all log is long (~500 lines)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 33 (9 by maintainers)

Most upvoted comments

I didn’t solve problem with Ubuntu, but i ran it to working sample.

  1. I used windows10 + virtualbox6.1.38

  2. Installed Debian11.5 (on virtualbox) - https://www.debian.org/CD/live/

    • make
    • openssh
    • wget
    • tmux
    • mosquitto

    And solved two problems with debian: 2.1 # USER IS NOT IN THE SUDOERS FILE : https://losst.ru/oshibka-user-is-not-in-the-sudoers-file-v-ubuntu 2.2 debian package has no installation candidate: https://www.cyberithub.com/solved-package-has-no-installation-candidate-in-debian/

    (All of this we do in terminal1)

  3. Installed Docker + docker-compose 1.29.2

    https://docs.docker.com/engine/install/debian/ docker main link https://www.bundleapps.io/blog/docker-series/pt-1-installing-docker-and-docker-compose link to install (Ru lang)

    3.1. Uninstall any previous versions if you have installed them. $ sudo apt-get remove docker docker-engine docker.io containerd runc

    3.2. Update your system and install the required dependencies. (I didn’t do the second line) $ sudo apt-get update $ sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

    3.3. Set up a repository $ sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release

    3.4. For security purposes, add the official GPG Docker key. $ sudo mkdir -p /etc/apt/keyrings

    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

    3.5. Set up a stable repository. $ echo \ "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

    3.6. Install the latest version of Docker along with all its dependencies. $ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io

    3.7. Instead of the last line, you can use below command and install latest docker-compose right away BUT!! you need 1.29.2 compose anyway!! $ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

    3.8. But you will probably need to install docker-compose of a certain version, for this we use $ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

    3.9. Give execute permissions to the binary file: $ sudo chmod +x /usr/local/bin/docker-compose

    Note: If the docker-compose command does not work after installation, check the installation path. You can also create a symbolic link to /usr/bin or any other directory. Example: $ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

    3.10. Checking the installation docker-compose $ docker-compose --version answer: docker-compose version , build 1110ad01

  4. Installed Mainflux 4.1. install the latest version from github $ sudo apt update $ sudo git clone https://github.com/mainflux/mainflux.git 4.2. Check if there is a clone $ ls answer: папка1 папка2 … mainflux … 4.3. Go to the mainflux folder and run $ cd mainflux $ sudo make run

  5. Mainflux Cli - open another terminal2 (don’t close terminal1 with mainflux) 5.1. Download file $ wget https://github.com/mainflux/mainflux/releases/download/0.13.0/mainflux-cli_0.13.0_linux-amd64.tar.gz 5.2. Checking what has been downloaded $ ls Exapmle answer: Desktop mainflux Pictures Videos Documents mainflux-cli_0.13.0_linux-amd64.tar.gz Public Downloads Music Templates

    5.3. Extracted from the archive $ tar xvf mainflux-cli_0.13.0_linux-amd64.tar.gz Checking: Desktop mainflux Music Templates Documents mainflux-cli_0.13.0_linux-amd64 Pictures Videos Downloads mainflux-cli_0.13.0_linux-amd64.tar.gz Public

    5.4. Addressing through the name mainflux-cli_0.13.0_linux-amd64 is long and inconvenient, we will rename it to cli $ mv mainflux-cli_0.13.0_linux-amd64 cli $ ls answer: cli Desktop Documents Downloads mainflux mainflux-cli_0.13.0_linux-amd64.tar.gz Music Pictures Public Templates Videos

    5.5. Calling $ ./cli answer: Usage: mainflux-cli [command]

     Available Commands:
       bootstrap   Bootstrap management
       certs       Certificates management
       channels    Channels management
       completion  Generate the autocompletion script for the specified shell
       groups      Groups management
       health      Health Check
       help        Help about any command
       keys        Keys management
       messages    Send or read messages
       provision   Provision things and channels from a config file
       things      Things management
       users       Users management
    
     Flags:
       -a, --auth-url string        Auth service URL (default "http://localhost")
       -b, --bootstrap-url string   Bootstrap service URL (default "http://localhost")
       -e, --certs-url string       Certs service URL (default "http://localhost")
       -c, --config string          Config path
       -y, --content-type string    Message content type (default "application/senml+json")
       -h, --help                   help for mainflux-cli
       -p, --http-url string        HTTP adapter URL (default "http://localhost/http")
       -i, --insecure               Do not check for TLS cert
       -l, --limit uint             Limit query parameter (default 100)
       -n, --name string            Name query parameter
       -o, --offset uint            Offset query parameter
       -r, --raw                    Enables raw output mode for easier parsing of output
       -t, --things-url string      Things service URL (default "http://localhost")
       -u, --users-url string       Users service URL (default "http://localhost")
    
     Use "mainflux-cli [command] --help" for more information about a command.
    

Then you can do by ./cli what you need

@manuio I creaded few users, two things + channel, and send message thing2->thing1 by mosquitto_sub/_pub. Also connect from windows10 to jaeger (http://salmon.local:16686/) and saw smthng (like things:identify) image image

On my .env file:

# Message Broker
MF_BROKER_TYPE=nats

## Nats
MF_NATS_PORT=4222
MF_NATS_URL=nats://broker:${MF_NATS_PORT}
.....
# Docker image tag
MF_RELEASE_TAG=latest```

ok, I already done docker rm $(docker ps -a -q) -f , docker volume rm $(docker volume ls | grep "mainflux") -f and docker network rm docker_mainflux-base-net as @dborovcanin said

This docker-compose -f docker/docker-compose down --rmi all -v --remove-orphans does not work

ERROR: .FileNotFoundError: [Errno 2] No such file or directory: './docker/docker-compose'

works next: docker-compose -f docker/docker-compose.yml down --rmi all -v --remove-orphans

@dborovcanin @kitty7c6 Oh yes my bad, I thought that it wasn’t done for core services. In that case maybe you are not using latest images but 0.13.0 but you are using the latest docker-compose. What is sure is that the MF_BROKER_URL envar (or the MF_NATS_URL) is not properly set.