在不同端口上的docker mysql [英] docker mysql on different port

查看:158
本文介绍了在不同端口上的docker mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改mysql docker容器的默认公开端口,但是如果我尝试使用此命令:

I want to change the default exposed port for mysql docker container, but if i try to use this command:

 docker run --detach --name=test-mysql -p 52000:52000  --env="MYSQL_ROOT_PASSWORD=mypassword" mysql

它不起作用. mysql -uroot -pmypassword -h 127.0.0.1 -P 52000 Warning: Using a password on the command line interface can be insecure. ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

It does not work. mysql -uroot -pmypassword -h 127.0.0.1 -P 52000 Warning: Using a password on the command line interface can be insecure. ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

如果我使用标准端口3306:3306,那么它可以正常工作,但是我想更改端口.有可能吗?

If I use the standard port 3306:3306 then it works fine, but i want change the port. Is it possibile?

我已经尝试过-p 52000:3600,但是我总是得到:

I had already tried -p 52000:3600 , but i have always gotten:

mysql -uroot -pmypassword -h 127.0.0.1 -P 52000 Warning: Using a password on the command line interface can be insecure. ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

mysql -uroot -pmypassword -h 127.0.0.1 -P 52000 Warning: Using a password on the command line interface can be insecure. ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

推荐答案

您需要在(服务器的)首选TCP端口上映射容器端口3306:

You need to map the container-port 3306 on the prefered TCP port (of your server):

-p <host_port>:<container_port> (map container_port xx on host_port yy)

对于您的mysql

docker run --detach --name=test-mysql -p 52000:3306  --env="MYSQL_ROOT_PASSWORD=mypassword" mysql

这篇关于在不同端口上的docker mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆