search
HomeDatabaseRedisHow to use docker to start redis and access it remotely on Linux

1. Install docker on centos7

1. Install some necessary system tools

yum install -y yum-utils device-mapper-persistent-data lvm2

2. Install docker’s yum source

yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo	# 中央仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo	# 阿里仓库

3. Install docker

yum install docker-ce  # 由于 repo 中默认只开启 stable 仓库,故这里安装的是最新稳定版

You can view all docker versions in all warehouses and select a specific version to install

yum list docker-ce --showduplicates | sort -r

How to use docker to start redis and access it remotely on Linux

yum install docker-ce-20.10.9.ce

4. Start the docker service

systemctl start docker	# 启动 Docker 
systemctl enable  docker	# 开机自启

5. Verify that docker

 docker version

has client and service parts, indicating that docker installation and startup are both Successful

How to use docker to start redis and access it remotely on Linux

2. Docker installs redis and starts it

1. Docker pulls the redis image

docker pull redis

2. View the local image

docker images

How to use docker to start redis and access it remotely on Linux

3. Mount the configuration file

The default redis installed by docker It can only be connected locally and cannot be accessed remotely, so you need to manually mount the external redis configuration file.

(1) Create a directory structure to store redis configuration files and data in any Linux directory: /docker/redis/conf, /docker/redis/data.

(2) Download the configuration file redis.conf from the official website and place it in the configuration file directory /docker/redis/conf.

(3) Modify the following configuration:

  • 1) bind 127.0.0.1: Comment out this part, which restricts redis to local access only

  • 2) protected-mode no: The default is yes, the protected mode is turned on, and restricted to local access

  • 3) requirepass 123456: Configure the redis connection password, the default is Commented

  • 4) dir ./: Change the local redis database storage folder (optional)

  • 5) appendonly yes: redis persistence ization, once this redis is turned on, it will not be automatically cleared every time it is restarted

4. Create a container and start the redis server

docker run -itd -p 6379:6379 --name lhjredis -v /docker/redis/conf/redis.conf:/etc/redis/redis.conf -v /docker/redis/data:/data redis redis-server /etc/redis/redis.conf

1) –name: Give the container a name;

2) -p: Port mapping (host port: container port);

3) -v: Mount custom configuration (Customized configuration: internal configuration of the container);

This command has two mounts: the customized redis configuration on Linux (/docker/redis/conf/redis.conf) is mounted to the container The default configuration file /etc/redis/redis.conf of the redis application in the container; the customized data storage directory (/docker/redis/data) on Linux is mounted to the default data storage directory (/data) of the redis application in the container.

In this way, the redis application in the docker container will use the customized configuration file on Linux, and the data of the redis application in the docker container will be placed in the customized data storage directory on Linux.

4) -d: running in the background;

5) redis-server --appendonly yes: Execute the redis-server startup command in the container and open the redis persistence configuration;

5. Start successfully, check the status

docker ps

How to use docker to start redis and access it remotely on Linux

##6. Enter the started container

docker exec -it myredis  /bin/bash

How to use docker to start redis and access it remotely on Linux

Execute the

docker exec -it container name/bin/bash command to enter the started container;

exit command You can exit the container

7. Use the redis client in the container

redis-cli

How to use docker to start redis and access it remotely on Linux

After entering the container, use the above command Start the Redis client, which will connect to your local Redis server.

If you are connecting to redis of other servers, you need to add parameters (host address, port number, password)

redis-cli -h xx.xxx.xx.xxx -p 6379 -a xxx

8. Use the Redis Desktop Manager client to connect


How to use docker to start redis and access it remotely on Linux

## Note

    When an error is reported when starting the container port, you can use netstat -lntp | grep 6379 to check which program is occupying it
  • You can use sudo kill 6379 kills the program occupying the port
  • If you use Alibaba Cloud, etc., please be sure to open the corresponding port

The above is the detailed content of How to use docker to start redis and access it remotely on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Redis: Beyond SQL - The NoSQL PerspectiveRedis: Beyond SQL - The NoSQL PerspectiveMay 08, 2025 am 12:25 AM

Redis goes beyond SQL databases because of its high performance and flexibility. 1) Redis achieves extremely fast read and write speed through memory storage. 2) It supports a variety of data structures, such as lists and collections, suitable for complex data processing. 3) Single-threaded model simplifies development, but high concurrency may become a bottleneck.

Redis: A Comparison to Traditional Database ServersRedis: A Comparison to Traditional Database ServersMay 07, 2025 am 12:09 AM

Redis is superior to traditional databases in high concurrency and low latency scenarios, but is not suitable for complex queries and transaction processing. 1.Redis uses memory storage, fast read and write speed, suitable for high concurrency and low latency requirements. 2. Traditional databases are based on disk, support complex queries and transaction processing, and have strong data consistency and persistence. 3. Redis is suitable as a supplement or substitute for traditional databases, but it needs to be selected according to specific business needs.

Redis: Introduction to a Powerful In-Memory Data StoreRedis: Introduction to a Powerful In-Memory Data StoreMay 06, 2025 am 12:08 AM

Redisisahigh-performancein-memorydatastructurestorethatexcelsinspeedandversatility.1)Itsupportsvariousdatastructureslikestrings,lists,andsets.2)Redisisanin-memorydatabasewithpersistenceoptions,ensuringfastperformanceanddatasafety.3)Itoffersatomicoper

Is Redis Primarily a Database?Is Redis Primarily a Database?May 05, 2025 am 12:07 AM

Redis is primarily a database, but it is more than just a database. 1. As a database, Redis supports persistence and is suitable for high-performance needs. 2. As a cache, Redis improves application response speed. 3. As a message broker, Redis supports publish-subscribe mode, suitable for real-time communication.

Redis: Database, Server, or Something Else?Redis: Database, Server, or Something Else?May 04, 2025 am 12:08 AM

Redisisamultifacetedtoolthatservesasadatabase,server,andmore.Itfunctionsasanin-memorydatastructurestore,supportsvariousdatastructures,andcanbeusedasacache,messagebroker,sessionstorage,andfordistributedlocking.

Redis: Unveiling Its Purpose and Key ApplicationsRedis: Unveiling Its Purpose and Key ApplicationsMay 03, 2025 am 12:11 AM

Redisisanopen-source,in-memorydatastructurestoreusedasadatabase,cache,andmessagebroker,excellinginspeedandversatility.Itiswidelyusedforcaching,real-timeanalytics,sessionmanagement,andleaderboardsduetoitssupportforvariousdatastructuresandfastdataacces

Redis: A Guide to Key-Value Data StoresRedis: A Guide to Key-Value Data StoresMay 02, 2025 am 12:10 AM

Redis is an open source memory data structure storage used as a database, cache and message broker, suitable for scenarios where fast response and high concurrency are required. 1.Redis uses memory to store data and provides microsecond read and write speed. 2. It supports a variety of data structures, such as strings, lists, collections, etc. 3. Redis realizes data persistence through RDB and AOF mechanisms. 4. Use single-threaded model and multiplexing technology to handle requests efficiently. 5. Performance optimization strategies include LRU algorithm and cluster mode.

Redis: Caching, Session Management, and MoreRedis: Caching, Session Management, and MoreMay 01, 2025 am 12:03 AM

Redis's functions mainly include cache, session management and other functions: 1) The cache function stores data through memory to improve reading speed, and is suitable for high-frequency access scenarios such as e-commerce websites; 2) The session management function shares session data in a distributed system and automatically cleans it through an expiration time mechanism; 3) Other functions such as publish-subscribe mode, distributed locks and counters, suitable for real-time message push and multi-threaded systems and other scenarios.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version