Home > other >  Docker mysql port mapping problem
Docker mysql port mapping problem

Time:09-18

Sudo docker run - the name first - mysql2 - p, 3306:3306 - e MYSQL \ _ROOT \ _PASSWORD=123456 - d MYSQL
Generated container for
087 e18f3ab85 0977 f3a915e5 "docker - the entrypoint... "23 seconds line Up to 20 seconds 0.0.0.0:3306 - & gt; 3306/TCP first - mysql2
Sudo docker run - the name first - mysql2 - p, 3308:3308 - e MYSQL \ _ROOT \ _PASSWORD=123456 - d MYSQL
Generated container for
0977 f3a915e5 cbe8dad89801 "docker - the entrypoint... "5 minutes line Up 5 minutes 3306/TCP, 0.0.0.0:3308 - & gt; 3308/TCP first - mysql1

Can see the port 3308 to create the container in front of the port number that a list of more than 3306/TCP, not sure whether this reason, in with the client to access mysql can only access port 3306, 3308 cannot be accessed,
Not has created problems, if only use the -p 3308:3308 created in the port number that a column is still take 3306/TCP, is no way to access to the client,
Is there any great god under the guidance is what problem

CodePudding user response:

I have never seen the mysql installation in a docker environment service, I give a suggestion and see if it is feasible,
A mysql container:
Sudo docker run - the name first - mysql2 - p, 13306:3306 - e MYSQL \ _ROOT \ _PASSWORD=123456 - d MYSQL
Mysql container 2:
Sudo docker run - the name first - mysql2 - p, 13307:3306 - e MYSQL \ _ROOT \ _PASSWORD=123456 - d MYSQL
Whether this is launched two containers use ports 13306 and 13307 respectively

CodePudding user response:

The inside of the container port is only 3306, which is the default port mysql, unless you change the mysql Dockerfile mirror,

CodePudding user response:

The dock of the run - p external host port: docker internal service port


3308 you want to access from outside, you ensure that the corresponding dockr container is mysql port 3308,
Or your intention should be written in 3308: -p 3306 ,

CodePudding user response:

If accessed through the Link, it is using a expose port, if you are hosting + port mapping, use the port mapping

CodePudding user response:

The building the second execution is wrong, the port should be hosting the 3308 mapping of container port 3306, mysql is the default port 3306, the building will be the second command returns the result of the implementation of 3306/TCP reason is that this is the default port container, the container is not port 3308, so the building when using a client connection will be unable to connect

CodePudding user response:

Good learning

CodePudding user response:

In general, mysql docker mirror's default IP is 3306
You can do an own mirror, mirror in the mysql you can install two mysql database, make its port of 3306 and 3308 respectively
Container is generated by the mirror again
Or
The mirror, you can use your original launched two containers, use external port 3308 - p 3308:3306

CodePudding user response:

Mysql connection by default port is 3306
You don't do special configuration that 3308 is not even to mysql
  • Related