MySQL connection on locahost with mariadb container fails - docker

Issue
I cannot connect with MySQL from the host the MariaDB Container is running from. Here are some infos concerning the environment:
docker compose-file
version: '3.1'
services:
db:
image: mariadb
restart: always
environment:
BIND-ADDRESS: 0.0.0.0
MYSQL_ROOT_PASSWORD: example
ports:
- 3306:3006
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Connecting with the container via docker exec -it rancherclientplatform_db_1 /bin/bash and the connecting with mysql -uroot -p unsurprisingly works.
GRANTS
Grants are as follows:
MariaDB [(none)]> SHOW GRANTS;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root#localhost
|
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD '*57237BB49761F29AB9724BA084E811D70C12393D' WITH GRANT OPTION |
| GRANT PROXY ON ''#'%' TO 'root'#'localhost' WITH GRANT OPTION
|
+----------------------------------------------------------------------------------------------------------------------------------------+
On the host
No when I try to connect on the host, neither
mysql -uroot -p nor
mysql -hlocalhost -uroot -p nor
mysql -h127.0.0.1 -uroot -p
work. The first 2 fail with a socket error, -h127.0.0.1 fails with
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"
The port 3306 itself seems to be published to the host properly, as
nmap -p3306 localhost delivers
PORT STATE SERVICE
3306/tcp open mysql
Any ideas on what to do here?

MariaDB default port is 3306.
so :
ports:
- 3306:3006
you probably want to map port using 3306:3306 if you want to access mariadb on localhost using port 3306

Related

phpmyadmin can't connect to mariadb in docker

I'm trying to connect a phpmyadmin container to a nginx container with mariadb downloaded.
I can access to phpmyadmin web site, but I can't log in to.
An error code Cannot log in to the MySQL server and mysqli::real_connect(): (HY000/2002): Connection refused will appear.
I made a bridge network "test-net", and connected the phpmyadmin container and the nginx container to the network. I commanded docker run -d --name phpmyadmin -e PMA_HOST=web -e PMA_PORT=3306 -p 8081:80 phpmyadmin/phpmyadmin for the phpmyadmin. Web is the nginx container and 3306 is my mariadb port number.
How can I log in to my database in phpmyadmin?

Cannot connect to docker container (redis) in host mode

This probably just related to WSL in general but Redis is my use case.
This works fine and I can connect like:
docker exec -it redis-1 redis-cli -c -p 7001 -a Password123
But I cannot make any connections from my local windows pc to the container. I get
Could not connect: Error 10061 connecting to host.docker.internal:7001. No connection could be made because the target machine actively refused it.
This is the same error when the container isn't running, so not sure if it's a docker issue or WSL?
version: '3.9'
services:
redis-cluster:
image: redis:latest
container_name: redis-cluster
command: redis-cli -a Password123 -p 7001 --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 --cluster-replicas 1 --cluster-yes
depends_on:
- redis-1
- redis-2
- redis-3
- redis-4
- redis-5
- redis-6
network_mode: host
redis-1:
image: "redis:latest"
container_name: redis-1
network_mode: host
entrypoint: >
redis-server
--port 7001
--appendonly yes
--cluster-enabled yes
--cluster-config-file nodes.conf
--cluster-node-timeout 5000
--masterauth Password123
--requirepass Password123
--bind 0.0.0.0
--protected-mode no
# Five more the same as the above
According to the provided docker-compose.yml file, container ports are not exposed, so they are unreachable from the outside (your windows/wls host). Check here for the official reference. More about docker and ports here
As an example for redis-1 service, you should add the following to the definition.
...
redis-1:
ports:
- 7001:7001
...
...
The docker exec ... is working because the port is reachable from inside the container.

Docker compose can't access ports of other containers

I have 2 containers running with docker compose. One of the containers is executing a shell script which should check if the other container has already started and is running on port 9990.
Even though the container is starting, the shell script echos nothing.
keycloak:
image: jboss/keycloak:latest
volumes:
- ./imports/cache_reload/disable-theme-cache.cli:/opt/jboss/startup-scripts/disable-theme-cache.cli
- ./imports/themes/custom/:/opt/jboss/keycloak/themes/custom-theme/
- ./imports/realm/realm-export.json:/opt/jboss/realms/custom-import.json
environment:
DB_VENDOR: MYSQL
DB_ADDR: mysql
DB_DATABASE: keycloak
DB_USER: keycloak
DB_PASSWORD: password
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: Pa55w0rd
ports:
- 8080:8080
depends_on:
- mysql
keycloak_installer:
image: solr:6.6-alpine
volumes:
- ./imports/scripts/import-realm.sh:/docker-entrypoint-initdb.d/init.sh
depends_on:
- keycloak
The shell script is the following:
echo "MOIN LEUDE TRYMACS HIER!"
while ! nc -z localhost 9990; do
sleep 1
echo "Waiting for keycloak server startup 9990..."
echo "$(nc -z localhost 9990)"
done
The first echo is printed, but then nothing else is printed.
The container keycloak is running on Port 9990.
Please help, thanks
You have to understand more detail about network in docker compose.
To solve your issue, you need :
Add network in your docker compose file for each container (there is a default network but to understand the mechanism, you can define it explicitly). This must looks like this (under ports for example) for the first container (named keycloak):
ports:
- 8080:8080
networks:
- keycloak_network
On the second container (named keycloak_installer) (you must expose the port that you want to request in the first container):
depends_on:
- keycloak
networks:
- keycloak_network
On your script call explictly the second container which will be now available by the network. You must change your code by this :
nc -z keycloak_installer 9990

Docker compose ftpd-server access from host

I'm using trying to access a ftpd-server from the host
Using ftp localhost or ftp <my_ip>
But I'm getting ftp: connect: Connection refused
version: '3'
services:
ftpd-server:
container_name: ftpd-server
image: stilliard/pure-ftpd:hardened
ports:
- 21:21
- 20:20
- 30000-30009:30000-30009
volumes:
- './ftp/data:/home/username/'
- './ftp/pass:/etc/pure-ftpd/passwd'
environment:
PUBLICHOST: "0.0.0.0"
FTP_USER_NAME: "user"
FTP_USER_PASS: "pass"
FTP_USER_HOME: "/home/username"
restart: always
Since I'm using PUBLICHOST: "0.0.0.0" and port forward 21:21 I was expecting to be able to connect.
Docker Log
Removing ftpd-server ... done
Removing network mytest_default
No stopped containers
Creating network "mytest_default" with the default driver
Creating ftpd-server ...
Creating ftpd-server ... done
Attaching to ftpd-server
ftpd-server | Creating user...
ftpd-server | Password:
ftpd-server | Enter it again:
ftpd-server | Setting default port range to: 30000:30009
ftpd-server | Setting default max clients to: 5
ftpd-server | Setting default max connections per ip to: 5
ftpd-server | Starting Pure-FTPd:
ftpd-server | pure-ftpd -l puredb:/etc/pure-ftpd/pureftpd.pdb -E -j -R -P 0.0.0.0 -s -A -j -Z -H -4 -E -R -G -X -x -p 30000:30009 -c 5 -C 5
How can I achieve to connect from host machine to my ftp server on the container?
You can add network_mode: host to your service definition to make it work.
services:
ftpd-server:
# ...
network_mode: host
# ...
Then test with:
$ ftp -p localhost 21
Connected to localhost.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 5 allowed.
220-Local time is now 16:04. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 15 minutes of inactivity.
A working example on my side is as following:
version: "1.0"
services:
ftpd-server:
image: stilliard/pure-ftpd:hardened
ports:
- "21:21"
- "30000-30009:30000-30009"
volumes:
- './ftp/data:/home/username/'
- './ftp/pass:/etc/pure-ftpd/passwd'
environment:
PUBLICHOST: "0.0.0.0"
FTP_USER_NAME: "username"
FTP_USER_PASS: "changeme!"
FTP_USER_HOME: "/home/username"
restart: always
Adding line of "network_mode: host" would cause following error with latest Docker installation (for my case it's Docker version 20.10.13, build a224086 on a Windows 10 OS with WSL2 support):
"host" network_mode is incompatible with port_bindings
It's a guarding facility involved in newer version of docker to avoid mis-configuration of ports, check following link for details: https://forums.docker.com/t/docker-errors-invalidargument-host-network-mode-is-incompatible-with-port-bindings/103492.

iOS postgres in docker-compose with port mapping

I have the following docker compose:
version: '3'
services:
postgres:
container_name: test-psql
image: postgres:10.4-alpine
restart: always
ports:
- 5432:5432
volumes:
- ~/docker_data/postgres:/data/postgres
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
I start everything with docker-compose up and then docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4cae94afaa6 postgres:10.4-alpine "docker-entrypoint.s…" 48 seconds ago Up 47 seconds 0.0.0.0:5432->5432/tcp test-psql
But when trying to connect to it with psql
psql -h localhost -U test
I get the error
psql: could not connect to server: Connection refused
Is the server running on host “localhost” (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host “localhost” (127.0.0.1) and accepting
TCP/IP connections on port 5432?
What you're trying is correct - I tested it on my end just in case and it's working as intended. I'd suggest checking your firewall configuration.

Resources