Docker installs redis master-slave container


Create dockerfile file

FROM centos:latest
RUN groupadd -r redis && useradd  -r -g redis redis
RUN yum -y update &&  yum -y install epel-release && yum -y install redis && yum -y install net-tools

From CentOS: latest get the latest CentOS version
Run groupadd - R redis & & useradd - R - G redis redis create a redis user and add the redis user to the redis group

Creating a redis image using dockerfile

Created in the current directory of the dockerfile file

docker build -t redis .
Description. Indicates that the context is to create an image of the dokcerfile file
After creation, you can view the generated image using docker image

Create a network docker

Because the default network cannot set a fixed address, we will create a custom network and specify the network segment: and name it mynetwork. The command is

As follows:
docker network create  --subnet=  mynetwork

Creating containers using mirrors

Master redis
docker run -itd --name  redis-master  --net mynetwork  -p 6380:6379  --ip  redis 
Parameter Description:
   See some documents for details

-d:   Run the container in the background and return the container ID;
-i:   Run the container in interactive mode, usually at the same time as - t;
-p:   Port mapping, in the format: host (host) port: container port
-t:   Reassign a pseudo input terminal to the container, usually used with - I;
--IP: specify a fixed IP address for the container 
--Net: Specifies the network mode

From redis
docker run -itd --name  redis-slave  --net mynetwork  -p 6381:6379  --ip  redis 

View the IP address of the container
 docker network inspect mynetwork

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Recommended Today

Kubernetes cluster management tool K9s

Generally, after deploying k8s clusters, we either use kubectl command for cluster management or use bashroad’s UI management interface to manage clusters. Recently, we found a terminal based and easy-to-use project that allows us to quickly view, navigate, observe and solve some problems in our daily use of kubernetes. This is the K9s project (some […]