简体   繁体   中英

Can't connect to MySQL using Acumos_mariadb_service docker container

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?

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM