In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to achieve docker link container interconnection", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to achieve docker link container interconnection" article.
Container interconnection
First create a startup mysql container
Docker run-dti-- name db-- restart=always-e MYSQL_ROOT_PASSWORD=redhat-e MYSQL_DATABASE=blog mysql:5.6
Create a boot source container wordpress
# docker run-dti-- name container name-- restart=always-v local directory: in-container directory-p local port: container port-- link database container name: database container alias wordpress mirror docker run-- name blog-- restart=always-v / web:/var/www/html-p 80:80-- link db:mysql wordpress
When using the-link parameter, docker automatically shares the variables of the two containers. When accessing the database, it is no longer accessed through IP, but through the container name.
Execute in the container: env | grep-I hub_name, which displays the environment variables of the container
Lab: tomcat connects to mysql
Next, configure the msyql connection in the webapps of the tomcat container, and the data source can enter the container name of the mysql.
The-link parameter can connect two containers into a set of containers, which is generally used to connect mysql without mapping the port of mysql to the host.
For example, after tomcat and mysql establish link, you can directly ping the container name of mysql in tomcat.
Instead of writing the localhost or ip address in the file where tomcat configures the MySQL connection, you can directly write the mysql container name to connect to the mysql database.
Create launch mysql Container docker run-dti-- name mysql-- restart=always-e MYSQL_ROOT_PASSWORD=123456 mysql:5.6 create launch tomcat Container-- link connection mysql Container docker run-- dti-- name tomcat-- restart=always-p 8080 name mysql 8080-- link mysql-v / webapps:/usr/local/tomcat/webapps tomcat
Next, configure the msyql connection in the webapps of the tomcat container, and the data source can enter the container name of the mysql.
After tomcat and mysql establish link, you can directly ping the container name of mysql in tomcat.
In the file where tomcat configures the MySQL connection, there is no need to write the localhost or ip address, just write the mysql container name to connect to the mysql database.
The above is the content of this article on "how to achieve the interconnection of docker link containers". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.