Galera cluster in docker container goes down automatically - docker

I am creating galera cluster between 2 containers. Container-1 is in Node-1, and Container-2 is in Node-2, I am using this imagebitnami/mariadb-galera:latest
so my cluster got up. both DBs were synced for almost 10 minutes then all of sudden container 2 stopped.
when I checked logs of both containers I observe some issue in container 2.
following are container 2 logs
root#vm:~# docker logs mariadb-galera-2
mariadb 06:53:51.31
mariadb 06:53:51.31 Welcome to the Bitnami mariadb-galera container
mariadb 06:53:51.31 Subscribe to project updates by watching https://github.com/bitnami/containers
mariadb 06:53:51.31 Submit issues and feature requests at https://github.com/bitnami/containers/issues
mariadb 06:53:51.32
mariadb 06:53:51.32 INFO ==> ** Starting MariaDB setup **
mariadb 06:53:51.35 INFO ==> Validating settings in MYSQL_*/MARIADB_* env vars
mariadb 06:53:51.36 INFO ==> Initializing mariadb database
mariadb 06:53:51.39 INFO ==> Updating 'my.cnf' with custom configuration
mariadb 06:53:51.40 INFO ==> Setting slow_query_log option
mariadb 06:53:51.41 INFO ==> Setting long_query_time option
mariadb 06:53:51.43 INFO ==> Setting wsrep_node_name option
mariadb 06:53:51.45 INFO ==> Setting wsrep_node_address option
mariadb 06:53:51.46 INFO ==> Setting wsrep_cluster_name option
mariadb 06:53:51.48 INFO ==> Setting wsrep_sst_auth option
mariadb 06:53:52.47 INFO ==> Starting mariadb in background
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
mariadb 07:04:12.70 ERROR ==> WSREP did not become ready
mariadb 07:04:12.71 INFO ==> Stopping mariadb
Node 1 IP: 192.168.2.19
Node 2 IP: 192.168.2.113
open ports on both nodes: 3306, 4444, 4567, 4568
Container 1 on node 1
docker run -d --name mariadb-galera-2 \
-p 3306:3306 \
-p 4567:4567 \
-p 4444:4444 \
-p 4568:4568 \
-e MARIADB_GALERA_CLUSTER_NAME=my_galera1 \
-e MARIADB_GALERA_MARIABACKUP_USER=user2 \
-e MARIADB_GALERA_MARIABACKUP_PASSWORD=user2 \
-e MARIADB_ROOT_PASSWORD=A#123 \
-e MARIADB_GALERA_CLUSTER_BOOTSTRAP=yes \
-e MARIADB_USER=user \
-e MARIADB_PASSWORD=user \
-e MARIADB_DATABASE=my_database1 \
-e MARIADB_REPLICATION_USER=repuser \
-e MARIADB_REPLICATION_PASSWORD=repuser \
-e MARIADB_EXTRA_FLAGS="--wsrep_provider_options=ist.recv_addr=192.168.2.19:4568;ist.recv_bind=0.0.0.0:4568 --wsrep_node_incoming_address=192.168.2.19 --wsrep_sst_receive_address=192.168.2.19 --wsrep_cluster_address=gcomm://" \
bitnami/mariadb-galera:latest
Container 2 on node 2
docker run -d --name mariadb-galera-2 --init \
-p 3306:3306 \
-p 4567:4567 \
-p 4444:4444 \
-p 4568:4568 \
-e MARIADB_GALERA_CLUSTER_NAME=my_galera1 \
-e MARIADB_GALERA_MARIABACKUP_USER=user2 \
-e MARIADB_GALERA_MARIABACKUP_PASSWORD=user2 \
-e MARIADB_ROOT_PASSWORD=B#123 \
-e MARIADB_REPLICATION_USER=repuser \
-e MARIADB_REPLICATION_PASSWORD=repuser \
-e MARIADB_EXTRA_FLAGS="--wsrep_provider_options=ist.recv_addr=192.168.2.113:4568;ist.recv_bind=0.0.0.0:4568 --wsrep_node_incoming_address=192.168.2.113 --wsrep_sst_receive_address=192.168.2.113 --wsrep_cluster_address=gcomm://192.168.2.19" \
bitnami/mariadb-galera:latest
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I searched this issue password for root user is not getting passed.
I checked env variable with docker exec -it mariadb-galera-2 env and password is being pasted correctly.
PATH=/opt/bitnami/common/bin:/opt/bitnami/common/sbin:/opt/bitnami/mariadb/bin:/opt/bitnami/mariadb/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=2ced7312bfe4
TERM=xterm
MARIADB_GALERA_CLUSTER_NAME=my_galera1
MARIADB_GALERA_MARIABACKUP_USER=user2
MARIADB_GALERA_MARIABACKUP_PASSWORD=user2
MARIADB_ROOT_PASSWORD=B#123
MARIADB_REPLICATION_USER=repuser
MARIADB_REPLICATION_PASSWORD=repuser
MARIADB_EXTRA_FLAGS=--wsrep_provider_options=ist.recv_addr=192.168.2.113:4568;ist.recv_bind=0.0.0.0:4568 --wsrep_node_incoming_address=192.168.2.113 --wsrep_sst_receive_address=192.168.2.113 --wsrep_cluster_address=gcomm://192.168.2.19
HOME=/
OS_ARCH=amd64
OS_FLAVOUR=debian-11
OS_NAME=linux
APP_VERSION=10.10.2
BITNAMI_APP_NAME=mariadb-galera
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I also got suggestion of using -e MARIADB_ALLOW_EMPTY_PASSWORD=yes OR -e ALLOW_EMPTY_PASSWORD=yes
with this -e MARIADB_ALLOW_EMPTY_PASSWORD=yes both containers are not starting.
with this -e ALLOW_EMPTY_PASSWORD=yes container1 start but mariaDB in container 2 is not able to start and hence stopped.

Related

cannot connect schema registry kafka

I'm trying to run confluent schema registry via docker image (on Mac os Catalina and Docker version 19.03.12)
docker run --network="host" -e \
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL=localhost:2181 \
-e SCHEMA_REGISTRY_HOST_NAME=localhost \
-e SCHEMA_REGISTRY_LISTENERS=http://0.0.0.0:8081 \
-e SCHEMA_REGISTRY_DEBUG=true confluentinc/cp-schema-registry
I'm running zookeper (3.5.8) and kafka server no the localmachine (no docker). The above picks (3.5.8 client of zookeper). However schema-registry is unable to connect.
[main-SendThread(localhost:2181)]
INFO org.apache.zookeeper.ClientCnxn -
Socket error occurred: localhost/127.0.0.1:2181: Connection refused
[main-SendThread(localhost:2181)]
INFO org.apache.zookeeper.ClientCnxn -
Opening socket connection to server localhost/127.0.0.1:2181.
Will not attempt to authenticate using SASL (unknown error)
I also tried mapping the port, instead of running it in the host network but have the same result
docker run -p 8081:8081 -e \
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL=host.docker.internal:2181 \
-e SCHEMA_REGISTRY_HOST_NAME=localhost \
-e SCHEMA_REGISTRY_LISTENERS=http://0.0.0.0:8081 \
-e SCHEMA_REGISTRY_DEBUG=true confluentinc/cp-schema-registry
Any ideas? Kafka BTW is running happily I can consume and produce messages.

Kafka FQDN in containers enviornment

Running kafka on a container and trying to create a new pgsql container on the same host.
the pgsql container keeps exiting and the logs indicates
ERROR: Failed to connect to Kafka at kafka.domain, check the docker run -e KAFKA_FQDN= value
the kafka container is built with the following attributes
docker run -d \
--name=app_kafka \
-e KAFKA_FQDN=localhost \
-v /var/app/kafka:/data/kafka \
-p 2181:2181 -p 9092:9092 \
app/kafka
the pgsql container with
docker run -d --name app_psql \
-h app-psql \
**-e KAFKA_FQDN=kafka.domain \
--add-host kafka.domain:172.17.0.1 \**
-e MEM=16 \
--shm-size=512m \
-v /var/app/config:/config \
-v /var/app/postgres/main:/data/main \
-v /var/app/postgres/ts:/data/ts \
-p 5432:5432 -p 9005:9005 -p 8080:8080 \
app/postgres
If i'm using docker0 ip address, the logs indicates no route to host, if i'm using the kafka docker ip, i'm getting connection refused.
I guess i'm missing something basic here that needs to be modified to my environment, but I'm lacking in knowledge here.
Will appreciate any assistance here.
You need edit container file hosts, you can pass a script in dockerFile like to
COPY dot.sh .
ENTRYPOINT ["sh","domain.sh"]
And domain.sh
#!/bin/sh
echo Environment container kafka is: "kafka.domain"
echo PGSQL container is "pgsql.domain"
echo "127.0.0.1 kafka.domain" >> /etc/hosts
echo "127.0.0.1 pgsql.domain" >> /etc/hosts
Feel free change ip or domain to needs.

Docker script not connecting when run first time (sql dump)

I am trying to run mysql through docker and scripts. Everything works fine, it runs it creates users and database. I can connect to it using workbench, but it does not run dump.sql
I get following error
Access denied for user 'userxx'#'localhost' (using password: YES)
But if I run script once again, it will connect and it will run dump.sql
Here is my script:
#!/bin/sh
echo "Starting DB..."
docker run --name test_db -d \
-e MYSQL_ROOT_PASSWORD=test2018 \
-e MYSQL_DATABASE=test -e MYSQL_USER=test_user -e MYSQL_PASSWORD=test2018 \
-p 3306:3306 \
mysql:latest
# Wait for the database service to start up.
echo "Waiting for DB to start up..."
docker exec test_db mysqladmin --silent --wait=30 -utest_user -ptest2018 ping || exit 1
# Run the setup script.
echo "Setting up initial data..."
docker exec -i test_db mysql -utest_user -ptest2018 test < dump.sql
What am I doing wrong ? Or is there way to run dump through Dockerfile, Since I couldnt manage to do it?
If you run docker run --help, you will see these flags
--health-cmd string Command to run to check health
--health-interval duration Time between running the check (ms|s|m|h) (default 0s)
--health-retries int Consecutive failures needed to report unhealthy
--health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)
--health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s)
So, you can use these command to check health with provided command. In your case, that command is
mysqladmin --silent -utest_user -ptest2018 ping
Now run as bellow
docker run --name test_db -d \
-e MYSQL_ROOT_PASSWORD=test2018 \
-e MYSQL_DATABASE=test -e MYSQL_USER=test_user -e MYSQL_PASSWORD=test2018 \
-p 3306:3306 \
--health-cmd="mysqladmin --silent -utest_user -ptest2018 ping" \
--health-interval="10s" \
--health-retries=6 \
mysql:latest
If you run docker ps, you will see
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d1d160ed7de mysql:latest "docker-entrypoint.s…" 16 seconds ago Up 16 seconds (health: starting) 0.0.0.0:3306->3306/tcp test_db
You will see health: starting in Status.
Finally you can use this to wait. When your mysql is ready, health will be healthy.
So modify your script as below
#!/bin/bash
docker run --name test_db -d \
-e MYSQL_ROOT_PASSWORD=test2018 \
-e MYSQL_DATABASE=test -e MYSQL_USER=test_user -e MYSQL_PASSWORD=test2018 \
-p 3306:3306 \
--health-cmd="mysqladmin --silent -utest_user -ptest2018 ping" \
--health-interval="10s" \
--health-retries=6 \
mysql:latest
# Wait for the database service to start up.
echo "Waiting for DB to start up..."
until [ $(docker inspect test_db --format '{{.State.Health.Status}}') == "healthy" ]
do
sleep 10
done
# Run the setup script.
echo "Setting up initial data..."
docker exec -i test_db mysql -utest_user -ptest2018 test < dump.sql
Here, following command returns health status
docker inspect test_db --format '{{.State.Health.Status}}'
Wait until it returns healthy.
Note: I have used #!/bin/bash in script
Instead of executing a dump, better mount your sql file to the init directory of MySQL’s image: /docker-entrypoint-initdb.d in the run command.
Simply add the switch:
-v $PWD/dump.sql:/docker-entrypoint-initdb.d/dump.sql
Pro tip :) don’t use latest tag. Always use stable, specific tag like 5, 5.7, 8 etc.

How to mount data directory?

I am not able to start percona mysql dockerized instance if I try to mount the data directory like this:
docker run --name percona57f -p 3384:3306 -v /my/custom3384:/etc/mysql/conf.d -v /storage/data3384:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=india3384 -e INIT_TOKUDB=1 -d percona/percona-server:5.7
The error is as shown below:
[ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
[ERROR] Aborting
The command will work if I do not include the data directory like this...
docker run --name percona57g -p 3384:3306 -v /my/custom3384:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=india3384 -e INIT_TOKUDB=1 -d percona/percona-server:5.7
But it is very important for me to mount the data directory on host machine. Any way to enable this -v /storage/data3384:/var/lib/mysql
Run this command before docker run:
chown 1001 /my/custom3384
This is the UID for the mysql user, as shown in the Dockerfile for the percona image:
https://github.com/percona/percona-docker/blob/master/percona-server/Dockerfile
RUN useradd -u 1001 -r -g 0 -s /sbin/nologin \
-c "Default Application User" mysql

Wordpress Access denied for user root with MySQL container

I'm trying to make MySQL instance available to other containers, I'm following this documentation mysql and this wordpress official documentation, I get this error
MySQL Connection Error: (1045) Access denied for user 'root'#'172.17.0.3' (using password: YES)
Code for MySQL instance
docker run -d --restart on-failure -v hatchery:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=Kerrigan \
-e MYSQL_DATABASE=zerglings --name spawning-pool mysql
Code for WordPress instance
docker run -d --name lair -p 8080:80 --link spawning-pool:mysql wordpress
How can I successfully link wordpress and mysql containers?
you need to pass in your database connection credentials via environment variables to wordpress:
docker run -d --name lair -p 8080:80 --link spawning-pool:mysql \
-e WORDPRESS_DB_HOST=mysql \
-e WORDPRESS_DB_NAME=zerglings \
-e WORDPRESS_DB_PASSWORD=zerglings wordpress
I have solved it by deleting everything and try starting it up again.
docker rm -v spawning-pool # -v Remove the volumes associated with the container
Remove the volume too
docker volume rm hatchery
Then I created the containers again
# create the volume
docker volume create hatchery
# MySQL instance
docker run -it -d --restart on-failure -v hatchery:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=Kerrigan \
-e MYSQL_DATABASE=zerglings --name spawning-pool mysql
# creating wordpress
docker run -d --name lair -p 8080:80 --link spawning-pool:mysql \
-e WORDPRESS_DB_HOST=mysql -e WORDPRESS_DB_NAME=zerglings
-e WORDPRESS_DB_PASSWORD=Kerrigan wordpress

Resources