In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What is the implementation method of Redis rapid deployment as a Docker container? to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Redis is a kind of memory key-value storage, which can preserve high-performance abstract data structures. Open source software is commonly used for database, messaging, and caching functions.
Docker is the leading toolkit for packaging applications into containers. It allows you to isolate software components to a separate environment with your own file system.
We will use Docker to quickly deploy Redis using the official image on Docker Hub. Compared with bare metal installation, Docker implements a simpler setup process and does not contaminate your host with new packages. Before continuing, make sure that a functioning Docker is installed on your host.
Introduction
The Redis image includes server components and the official CLI. It is pre-configured to start the server with the running default configuration value when you start the new container.
Variations of the image can be used to cover different Redis versions (5.0,6.0) and operating systems (Alpine and Debian). Browse the list of tags to find the best option for your environment.
The simplest deployment is as follows:
Docker run-- name redis-d-p 6379 redis:6.0
This will launch a new container called redisrunning Redis 6. 0. The-d flag is used to detach from the container. The server will run in the background until you use docker stop redis.
Redis listens on port 6379 by default. The-p flag binds this port to your host. Your application will be able to access Redis localhost:6379. Please note that this is not secure-if your machine is exposed to the Internet, anyone can access your Redis data!
Data storage
Redis supports a variety of persistence mechanisms to save your in-memory database to disk. The data is saved to a directory in the / data container. Because the Docker container is temporary, you need to mount the volume to this directory. Otherwise, when your container stops, your data will be lost.
Docker run-- name redis-d\-- v redis-data:/data redis:6.0-- save 60 1
The-save flag is passed to the Redis server. It configures the persistence policy to be used. This example writes database snapshot 60 every second. This operation is skipped unless 1 database writes have occurred since the last snapshot.
A called Docker volume redis-data is created by the-v flag. This stores your data outside the container so that it can still be accessed after a reboot. The volume will exist until it is removed from docker volumes rm redis-data by running.
Configure your server
The quickest way to add configuration parameters is to pass the CLI parameter to the Redis server as part of the docker run command. -save the above example illustrates this. Any content docker run after the image name in is passed to the command executed within the container. For Redis images, this command is the Redis server.
Using the CLI flag quickly becomes repetitive. You can make Redis use the configuration file by passing the path as the first parameter of the server. This file is usually located in / usr/local/etc/redis/redis.conf. Install redis.conf using Docker binding to obtain from the local file system mounted to the container:
Docker run-- name redis-d\-v redis-data:/data-v. / redis-conf:/usr/local/etc/redis redis:6.0 / usr/local/etc/redis.conf
Place a redis.confinside redis-conf in your working directory. Docker mounts this path into the container so that Redis can access the file specified in the docker run command.
Manage Redis security
By default, the Redis Docker image is configured to run Redis in unprotected mode. This makes it easier to access the Redis server from other Docker containers using the Docker network. However, this also means that anything that can reach your container has full access to your data.
Protected mode is a feature of Redis that responds only to unauthenticated queries sent from the loopback address of the host, such as localhost. You can add protected-mode yes to your redis.conf. When used with the Dockerized installation, this will cause Redis to be accessed only within its own container, which is usually not ideal.
You can add requirepass example to your redis.conf. Redis will only accept queries from clients that provide configured passwords. Redis 6 also supports more full-featured access control, allowing you to set up multiple user accounts with different permissions.
To use authentication, follow the instructions in the previous section to create an Redis configuration file and mount it into your container. If you do not want to set a password, simply add it to the Docker network required by the application to secure your installation. Do not bind port 6379 to your host without first setting authentication.
Use your Redis installation
Now that Redis is fully set up, you can continue to access it from the client. If you connect from the host, you can use the IP of the Docker container (adjusted according to the container name by running visible docker inspect redis) and port 6379.
To access Redis from another Docker container, it is best to join both containers to a Docker network:
Docker network create redisdocker run-name redis-network redis-d redis:6.0docker run-- name api-- network redis-d my-api:latest
Your application container will now be able to access Redis through port 6379 on the redis hostname. When they share a Docker network, Docker makes the container name accessible as a hostname.
You can manually interact with the database using the binaries contained in the redis-cli container image. Start your container in detached mode (- d) so that it runs in the background. Then use docker exec to run the redis-cli command:
Docker exec-it redis-container redis-cli
This will take you into the Redis CLI session within the container.
Generalization
Docker allows you to start new Redis instances quickly and easily without having to install software on your machine. Start your container with the official Docker image, then add a command flag or mount a configuration file to meet your needs.
Two things to always keep in mind are storage and security: if you need to use Redis persistence, you should use Docker volumes to avoid data loss. Keep in mind that Dockerized Redis defaults to unprotected mode and requires no authentication, so in the worst case, exposing port 6379 can be catastrophic.
This is the answer to the question about how to quickly deploy Redis as a Docker container. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.