How to connect after docker link runs?

  docker, question

I want to use mysql containers to create containers as described on hub

docker run --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8

docker run -d --name nx --link mysql:db nginx

Direct use of the base container did not connect successfully.

~# docker ps
 CONTAINER ID        IMAGE                    COMMAND                  CREATED              STATUS              PORTS                                            NAMES
 bf673d61f789        nginx                    "nginx -g 'daemon ..."   3 seconds ago        Up 2 seconds        80/tcp, 443/tcp                                  nx
 1ac01c685e9b        mysql:8                  "docker-entrypoint..."   About a minute ago   Up About a minute   3306/tcp                                         mysql

Localhost:3306 cannot be accessed in nginx: 3306

Pass a command
docker inspect -f "{{ .HostConfig.Links }}" proxy
Check that the connection is successful
Hosts in nginx       localhost
 ::1     localhost ip6-localhost ip6-loopback
 fe00::0 ip6-localnet
 ff00::0 ip6-mcastprefix
 ff02::1 ip6-allnodes
 ff02::2 ip6-allrouters      db 1ac01c685e9b mysql      8242073e142b

It seems a little casual,

It is quite different from what I expected localhost:3306.

Is there any way to use localhost:3306 after connection?

Link is to establish the network link of two containers, not to merge the network ports of the two containers! !
Visitlocalhost:3306Change to visitdb:3306The database service can be accessed successfully.