docker mysql on different port

2019-02-16 19:33发布

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

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

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 work fine, but i want change the port, it's possibile?

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

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 docker
1条回答
迷人小祖宗
2楼-- · 2019-02-16 20:11

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)

So for your mysql

docker run --detach --name=test-mysql -p 52000:3306  --env="MYSQL_ROOT_PASSWORD=mypassword" mysql
查看更多
登录 后发表回答