不同端口上的docker mysql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41637013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
docker mysql on different port
提问by lbottoni
I want to change the default exposed port for mysql docker container, but if i try to use this command:
我想更改 mysql docker 容器的默认公开端口,但如果我尝试使用此命令:
docker run --detach --name=test-mysql -p 52000:52000 --env="MYSQL_ROOT_PASSWORD=mypassword" mysql
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
这是行不通的。 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
If I use the standard port 3306:3306 then it works fine, but i want change the port. Is it possibile?
如果我使用标准端口 3306:3306 那么它工作正常,但我想更改端口。有可能吗?
I had already tried -p 52000:3600 , but i have always gotten:
我已经尝试过 -p 52000:3600 ,但我总是得到:
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
回答by lvthillo
You need to map the container-port 3306 on the prefered TCP port (of your server):
您需要在首选 TCP 端口(您的服务器)上映射容器端口 3306:
-p <host_port>:<container_port> (map container_port xx on host_port yy)
So for your mysql
所以对于你的 mysql
docker run --detach --name=test-mysql -p 52000:3306 --env="MYSQL_ROOT_PASSWORD=mypassword" mysql