How to connect after docker link is running?
天蓬老师
天蓬老师 2017-06-07 09:23:31
0
1
824

I want to use the mysql container and create the container according to the description on the 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 basic container failed to 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

Unable to access localhost:3306 in nginx

By command
docker inspect -f "{{ .HostConfig.Links }}" proxy
[/mysql:/nx/db]
Check that the connection is successful
hosts

in nginx
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.4      db 1ac01c685e9b mysql
172.17.0.6      8242073e142b

It seems a bit random,

It’s very different from the localhost:3306 I expected

Is there a way to use localhost:3306 after connecting?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
世界只因有你

Link is to establish a network link between two containers, not to merge the network ports of the two containers together! !
Replace the access localhost:3306 with the access db:3306 to successfully access the database service

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!