Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the interconnection of docker link containers

Shulou Source: shulou.com Published: 2022-06-01 05:39:51 09月28日 Update

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.

Tags: Container data content database interconnection configuration port next two parameters variables addresses data sources files articles directories knowledge articles input no Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MySQL Redmi Apple Linux