Docker installs redis master-slave container

Time:2021-12-1

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
EXPOSE 6379

explain: 
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: 172.10.0.0/16 and name it mynetwork. The command is

As follows:
docker network create  --subnet=172.10.0.0/16  mynetwork

Creating containers using mirrors

Master redis
docker run -itd --name  redis-master  --net mynetwork  -p 6380:6379  --ip 172.10.0.2  redis 
Parameter Description:
   See some documents for details
http://www.runoob.com/docker/docker-run-command.html
http://www.dockerinfo.net/docker%E5%AE%B9%E5%99%A8-2

-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 172.10.0.3  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 […]