Nextcloud in Docker & MySQL on Host - mysql

I'm running docker on my Raspberry Pi. I'm intending to run a few services locally (NextCloud, Bitwarden, etc) and want to use one MariaDB Instance, not one for each as most tutorial show. I've been trying to figure out how to make that work.
I installed mariadb on my RPI and nextcloud via Docker. I passed the MySQL environment variables to that container:
environment:
- MYSQL_PASSWORD=xxx
- MYSQL_DATABASE=dbname
- MYSQL_USER=user
- MYSQL_HOST=192.168.178.36
When I go to the NC initialization page and enter the data, it says Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused".
I addded "user#IP" to MySQL and granted it all access to the DB. The IP is the Docker-internal IP of the Container (172.xxx)

Related

Cirrus CI - Can't connect to MySQL additional container

I'm running a container on Cirrus CI, and in my .cirrus.yml, I've defined an additional_container to run a MySQL instance to test against as per the docs:
.cirrus.yml
container:
image: node:latest
additional_containers:
- name: mysql
image: mysql:8
port: 3306
cpu: 1.0
memory: 512Mi
env:
MYSQL_ROOT_PASSWORD: "pa55w0rd"
I'm trying to run a CREATE DATABASE command against that instance in one of my setup tasks:
...
mysql_setup_script:
- mysql -uroot -ppa55w0rd -P3306 -hlocalhost -e "CREATE DATABASE voluble_test;"
...
I've installed the MySQL client (but not the server, as this would defeat the object) on my testing container. However, MySQL acts as if it were connecting to a true localhost DB and looks for a locally-installed MySQL server, it appears - and fails with the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
That said, the Cirrus CI docs state that the MySQL instance should be available at localhost:
Tests will be able to access MySQL instance via localhost:3306.
I can't see an obvious way around this - any advice?
Using localhost will cause mysql not to use the network.
Use either 127.0.0.1 or your docker host IP, depending on network configs.
Notice that the error is not a network error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
"through socket '/var/run/mysqld/mysqld.sock'", that file does not point to a mysql socket inside your docker container.
Grab your docker host IP with:
$ docker network inspect bridge --format='{{ (index .IPAM.Config 0).Gateway}}'

Doctrine Connection Refused from Symfony Docker Container to MariaDB Container

Banging my head at 2:30 a.m.
I have three Docker containers MariaDB, Nginx and PhpFpm.
MariaDB opens up 3306/tcp - no exposed port because all container share the same Docker Network.
Symfony starts up in PhpFpm and is exposed via Nginx on port 8081.
So myhost.com:8081 shows my Symfony application.
When I docker exec bash into my PhpFpm container and execute bin/console doctrine:schema:create schema is created, MariaDB has a new table.
Of course I clear the cache and warm it up for APP_ENV=prod
var/log and var/cache have set correct permissions.
No matter what I do, when using the PDO connection within my Symfony application's controller I get an
Connection refused error
visible in my prod.log within the container.
I tried .env with several options, most prominent are:
DATABASE_URL="mysql://user:pass#hostname:8084/db" (here I set -p 8084:3306 for MariaDB Container)
and
DATABASE_URL="mysql://user:pass#mariadbcontainername:3306/db" (here I did not expose any DB port as mentioned above)
Does anyone have an idea where to look and what to test?
I can even verify that my bin/console doctrine... commands are already getting a Connection Refused error when I change the DATABASE_URL to a nonsense value.
P.S.: Due to server restrictions I don't use docker-compose but simply docker run.

Docker nodejs with mysql communication

I'm using 2 docker images one with my nodeJS backend server the other with my MySQL database. On the docker-compose file I'm defining the passwords, ports and hostnames correctly:
sql:
image: mysql:5.7.22
hostname: sql
ports:
- 3306:3306
secrets:
- db_root_pass
- db_user_pass
environment:
MYSQL_USER: user
MYSQL_PASSWORD_FILE: /run/secrets/db_user_pass
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_pass
provider:
image: monokilho/app:dev
hostname: provider
ports:
- 3000:3001
- 9221:9229
secrets:
- db_user_pass
command: node --inspect=0.0.0.0:9229 appModule.js
And on my DB_config.js file for NodeJS I have the connection setup like so:
db_config.host = 'sql';
db_config.port = '3306';
db_config.user = 'user';
db_config.password = fs.readFileSync('/run/secrets/db_user_pass', 'utf8');
db_config.database = 'app';
db_config.multipleStatements = true;
Problem is that although, using this exact configurations, docker connects Node to MySQL just fine on my local windows machine, when I upload the images to my remote linux server I continue to get:
Access denied for user 'user'#'8b2e56e566b2.network_default'
I've already remade the secrets, tried manually adding the passwords to the config on NodeJS and nothing... what makes it even weirder is that if I go on the MySQL container to connect directly or if I make another MySQL container and remotely connect it works, so I know the password input on MySQL config is correct and it is accepting remote connections.
Any suggestion what might be the difference between windows and linux for this behavior to happen? Thanks in advance.
PS: If needed windows is windows 10 and linux distro is ububtu 16.04.
EDIT: The access denied error appears on the mysql logs so the nodejs docker can reach the mysql docker and the network should be fine.
Apparently the mysql config was ignoring a sneaky \n on the password file allowing it to work normally with a command line connection, while on the nodejs it was bugging the connection.

Linkedin WhereHows - Docker Backend not able to connect to MySQL

When I try to connect WhereHows backend to MySQL DB in Docker environment I am getting following error message (I checked IP, Username and Password and all 3 are good):
1) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [wherehows]]
At the same time, WhereHows web is connecting without any problem.
Docker version is 17.12.0-ce and I am using following images:
wherehows/backend
wherehows/web
wherehows/mysql
This is my config file - /backend-service/conf/application.conf
# connection to wherehows mysql database
db.wherehows.driver = com.mysql.jdbc.Driver
db.wherehows.url="jdbc:mysql://localhost/wherehows?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false"
db.wherehows.username="wherehows"
db.wherehows.password="wherehows"

Container can't connect to MySql DB

I have one container running MySQL and want to connect to the DB from another container (Wordpress). When running the container locally on my laptop it can connect to the DB running on Bluemix. Running the same container on Bluemix
ice run --name=wordpress1 -p 80 -e WORDPRESS_DB_PASSWORD=xxx -e WORDPRESS_DB_HOST=129.41.234.102:3306 registry-ice.ng.bluemix.net/rhocheck/wordpress:latest
I get this errors:
Warning: mysqli::mysqli(): (HY000/2002): No route to host in - on line 10
The DB is up an running. I can connect even from a container on Bluemix I connected vie ssh
Any ideas?
I would use the ClearDB Service instead. The MySQL service is experimental. ClearDB is an awesome company that does hosted MySQL. Could you try binding CLearDB to your app/container and connect via that way?