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

Use the njs module to introduce js scripts in nginx configuration

Table of contents Preface 1. Install NJS module M...

Detailed explanation of MySQL index selection and optimization

Table of contents Index Model B+Tree Index select...

Implementation of modifying configuration files in Docker container

1. Enter the container docker run [option] image ...

JavaScript implements the detailed process of stack structure

Table of contents 1. Understanding the stack stru...

Solve the problems encountered when installing MySQL 8.0 on Win10 system

The problems and solutions encountered when insta...

Creation, constraints and deletion of foreign keys in MySQL

Preface After MySQL version 3.23.44, InnoDB engin...

Detailed explanation of MySql 5.7.17 free installation configuration tutorial

1. Download the mysql-5.7.17-winx64.zip installat...

How to use dl(dt,dd), ul(li), ol(li) in HTML

HTML <dl> Tag #Definition and Usage The <...

mysql installer community 8.0.12.0 installation graphic tutorial

This tutorial shares the installation of mysql in...

Creative About Us Web Page Design

Unique “About”-Pages A great way to distinguish yo...

Summary of 11 common mistakes made by MySQL call novices

Preface You may often receive warning emails from...

Detailed explanation of CSS3 flex box automatic filling writing

This article mainly introduces the detailed expla...

How to implement Docker Registry to build a private image warehouse

The image of the microservice will be uploaded to...

About the IE label LI text wrapping problem

I struggled with this for a long time, and after s...