using docker --link to mysql

2019-08-04 05:46发布

问题:

I need to be able to connect to te next docker db:

sudo docker run --name=cmydatabse -v /opt/mysql_data:/var/lib/mysql --env="MYSQL_ROOT_PASSWORD=mypassword" mysql:5.7

using a link command, I want to create a link so I can connect to this database using:

       mysql -u -p -h  Something  P:3306

Is this possible?

回答1:

Links are legacy from docker compose 2 and all recent docker versions.

The way to link your mysql container is using networks https://docs.docker.com/engine/userguide/networking/#user-defined-networks.

With a network the containers will recognize each other by the container name