简体   繁体   English

不同端口上的 docker mysql

[英]docker mysql on different port

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

If I use the standard port 3306:3306 then it works fine, but i want change the port.如果我使用标准端口 3306:3306 那么它工作正常,但我想更改端口。 Is it possibile?有可能吗?

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

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

there is also a second option:还有第二个选择:

don't map a port to another port but let mysql itself run directly on another port using the MYSQL_TCP_PORT -variable.不要将端口映射到另一个端口,而是让 mysql 本身使用MYSQL_TCP_PORT变量直接在另一个端口上运行。

example:例子:

docker run --detach --name=test-mysql --env="MYSQL_TCP_PORT=52000" mysql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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