Link between two containers

in my application i have the db url as jdbc:mysql//dockermysql:3306/mydb

and i launch the mysql db container with name dockermysql
then when i launch the application container i need to link it to mysql container
in docker run command i map it like

–link dockermysql:mysql

but i dont understand this command totally… why are we referring to image mysql here and simply not referring to dockermysql container alone

Hi shhl.basha333,

Docker recommends using the user-defined networks to facilitate communication between two containers instead of using --link .

You can see the Differences between user-defined bridges and the default bridge

Containers connected to the same user-defined bridge network automatically expose all ports to each other, and no ports to the outside world. This allows containerized applications to communicate with each other easily, without accidentally opening access to the outside world. Containers on the default bridge network can only access each other by IP addresses, unless you use the --link option, which is considered legacy. On a user-defined bridge network, containers can resolve each other by name or alias.