Docker learning notes — net core application container connects redis container through network bridge (environment: centos7)


The previous section shows how to connect the SQL server container through the application containerDocker learning notes — net core project container connecting to MSSQL container (environment: centos7)

This section demonstrates the installation of redis container, which is connected through the bridge


. net core project needs to support redis read-write function and configure relevant connection strings

The specific steps are as follows:

1. Install redis, create redis container and connect to the bridge

2. Modify the redis connection string in the. Net core project, rebuild the container, and restart the nginx direction proxy container

3. Test


Step 1: install redis, create redis container and connect to the bridge

It is very simple to install redis in docker. View the installable image through the following command

docker search redis

Pull the latest version of redis image, and default to the latest version

docker pull redis

Use the following command to run the redis container and connect to the network bridge created in the previous section

docker run --name=redistest -d -p 6379:6379 --network=test_network redis --requirepass 123456

– 456 is interpreted as: – 1236

6379:6379 indicates that the external can directly access the redis service through the host IP: 6379

Enter the redis container and perform the connection test through the redis cli command. The exit command means to exit the current container. If (error) noauth authentication required. Error occurs, the auth password is used for authentication

$ docker exec -it redis-test /bin/bash

$ redis-cli      

The host IP: port can also be accessed externally

Step 2: modify the redis connection string in the. Net core project and rebuild the container

Configure the redis container name redistest created in the first step to the redis connection string below;

Then re create the. Net core application project image and container, and restart the ngxin reverse proxy

docker build -t myapidemo:1.1 .

docker run --name=myapidemo -d -p 9020:80 --network=test_network myapidemo:1.1

 Step 3: test, insert a redis record by calling API interface


The results are as follows: