Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

260
Visualizações
Cant connect to Mysql docker container from host

Im running docker on windows and I start up a docker container with MySql like this

docker run -p 3306:3306 --name test -e MYSQL_ROOT_PASSWORD=secret-pw -d mysql/mysql-server:5.5

Then on my host I start up Mysql workbench and try to connect but it does not work.

docker inspect test reveal IP address on 172.17.0.2 but when I ping this I get no reply

Got this working on a linux host and I am pretty sure I have done the exact same steps

What am I doing wrong ?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Help Doc: https://docs.docker.com/samples/library/mysql/

Image link: https://store.docker.com/images/mysql

Command: docker run --name mysql_container_name --expose=3306 -p 3306 -v /my/own/datadir:/path/to/data/dir -e MYSQL_ROOT_PASSWORD=root_pwd -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

  • mysql_container_name: docker container name
  • expose: contaner exposeing port
  • p: host buinding port
  • /path/to/data/dir: share path between container and host
  • root_pwd: mysql root password
  • tag: repository tag
  • utf8mb4: mysql server character set and collation type
  • utf8mb4_unicode_ci: mysql server character set and collation type

Example: docker run --expose=3306 -p 3306 --name mysql -v /my/own/datadir:/opt/mysql -e MYSQL_ROOT_PASSWORD=0112358139 -d mysql:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

Following steps to connect remotely:

docker exec -it mydb bash  --> this will connect to mySql container. 

echo "bind-address = 0.0.0.0" >> /etc/mysql/my.cnf   --> this will update the my.cnf file. 

service mysql restart --> restart the mySql service. 

exit --> the mySql container. 

docker inspect mysql | grep IPAddress --> grep the IP address of the contaner. 

mysql -h 172.17.0.2 -u root –p  --> remotely connect to the mySql. 
over 4 years ago · Santiago Trujillo Relatório

0

Your host 3306 port should be forwarding to the container, so try connecting on localhost:3306. When I tried to replicate, got the "Host 172.17.0.1 not allowed to connect to this MySQL server" which means it got through at least.

More on the latter: https://github.com/fideloper/docker-mysql/issues/10

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda