How to deploy and start redis in docker

How to deploy and start redis in docker

Deploy redis in docker

First install Docker in Linux, then start the Docker service

Start Docker in Centos7
 systemctl start docker //Start docker
 systemctl stop docker //Stop docker
 systemctl restart docker //Restart docker

Find the image you want to pull

1. Use docker search image name to search for the image directly in Linux
docker search image name
2. Search on the DockerHub website

Pull the image using docker pull image name

docker pull redis //Do not specify a version number, pull the latest one by default.
docker pull redis:6.0.8

After pulling the image, use docker images to view the pulled image

docker images
docker rmi image ID //delete the image

Configure redis before running

The redis.conf configuration file can be downloaded at http://download.redis.io/redis-stable/redis.conf
Use mkdir /usr/local/docker to create a docker directory on the host machine. vi /usr/local/docker/redis.conf to create the redis configuration file redis.conf in docker.
Replace the downloaded redis.conf file or copy the content to the configuration file you created and then modify the configuration bind 127.0.0.1 //127.0.0.1 restricts access to the local machine only and changes it to 0.0.0.0

protected-mode no # The default is yes, which turns on protected mode and limits access to local devices daemonize no The default is no, and changing to yes means starting redis as a daemon process. Yes will cause the configuration file to fail to start redis (it will exit as soon as it is turned on)

Run the specified image

1. $ docker run -itd --name redis-test -p 6379:6379 redis

2. $ docker run -itd -p 192.168.220.129:6379:6379 --name redis -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/data redis redis-server /etc/redis/redis.conf 

-d Run as a daemon thread (background run)
-i runs the container in interactive mode -t reallocates a pseudo input terminal for the container -p maps port 6379 of the container service to port 6379 of the host machine. The outside world can directly access the Redis service through the host ip:6379.

 //It may not work without -it because, for Docker container to run in the background, there must be a foreground process. The commands run by the container are not those that are always suspended (such as running top, tail), and it will automatically exit -v /usr/local/docker/redis.conf:/etc/redis/redis.conf //Mount the redis.conf configured on the host to the specified location in the container -v /usr/local/docker/data:/data //Mount the persistent data of redis to the host for data backup redis-server /etc/redis/redis.conf //Start redis according to the configuration of redis.conf –appendonly yes //Data persistence after redis starts

Operate the container after running

1. View the running container docker ps
2. View all containers docker ps -a
3. Enter the container docker exec -it container ID /bin/bash
4. Stop all containers docker stop $(docker ps -q)
5. Delete all containers docker rm $(docker ps -aq)
6. Stop and delete all docker stop $(docker ps -q) & docker rm $(docker ps -aq)

An error occurred

Docker container port mapping error

docker: Error response from daemon: driver failed programming external connectivity on endpoint lamp3 (46b7917c940f7358948e55ec2df69a4dec2c6c7071b002bd374e8dbf0d40022c): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 86 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name.

Workaround
Restart the Docker service

systemctl restart docker

This is the end of this article about how to deploy and start redis in docker. For more information about deploying and starting redis in docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Implementation of Docker deployment of Django+Mysql+Redis+Gunicorn+Nginx
  • How to deploy redis in linux environment and install it in docker
  • How to deploy redis cluster with docker
  • Docker deployment SpringBoot project integration Redis image for access counting sample code
  • Docker starts Redis and sets the password

<<:  JavaScript programming through Matlab centroid algorithm positioning learning

>>:  HTML table markup tutorial (40): Dark border color attribute of the header BORDERCOLORDARK

Recommend

Sitemesh tutorial - page decoration technology principles and applications

1. Basic Concepts 1. Sitemesh is a page decoratio...

CSS delivery address parallelogram line style example code

The code looks like this: // Line style of the pa...

The problem of Vue+tsx using slot is not replaced

Table of contents Preface Find the problem solve ...

Tutorial on how to use profile in MySQL

What is a profile? We can use it when we want to ...

Detailed explanation of MySQL high availability architecture

Table of contents introduction MySQL High Availab...

JavaScript code to implement a simple calculator

This article example shares the specific code of ...

Detailed steps for installing ros2 in docker

Table of contents Main topic 1. Install Docker on...

Vue+Echart bar chart realizes epidemic data statistics

Table of contents 1. First install echarts in the...

Detailed explanation of JavaScript stack and copy

Table of contents 1. Definition of stack 2. JS st...

How to optimize the slow Like fuzzy query in MySQL

Table of contents 1. Introduction: 2. The first i...

Introducing icons by implementing custom components based on Vue

Preface In project development, there are many wa...

Detailed explanation of CSS style sheets and format layout

Style Sheets CSS (Cascading Style Sheets) is used...