0

I have installed the maria_db service as a docker component of Acumos. Even if the docker container is running, I am not able to execute the following command:

mysql -h localhost -P 3306 --user=root --password=98dceddd-a364-4f76-abe0-b0dc7283fc7f -e 'SHOW DATABASES;'

because I get the error as error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

However, if I login into the docker container using:

docker exec -it acumos_mariadb_db_service bash

and run the same command, it works.

How can I login to the MySQL server from outside the container without getting any error?

xKobalt
  • 1,498
  • 2
  • 13
  • 19

2 Answers2

0

Is docker exposing port 3306 on localhost?

 docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag -p 3306:3306 

Docker containers don't expose ports to the host by default; you need to set them up yourself. In the example above, you're mapping the container's port 3306 to your local machine's 3306.

Details for how to set up container networking are here: https://docs.docker.com/config/containers/container-networking/

Tim Howland
  • 7,919
  • 4
  • 28
  • 46
  • Yes, the docker container is exposing port 3306. With a docker ps command , the ports for the container is displayed as 0.0.0.0:3306->3306/tcp – Shabnam Sultana Jul 20 '20 at 16:16
0

I finally fixed the issue. Problem was the mariadb server runs as a docker image exposing port 3306 and the mariadb client is installed on the same local machine also using port 3306. Change the port mapping like 0.0.0.0:3307->3306/tcp solved the issue.