【docker&redis】用docker容器运行单机redis

一、实验环境

操作系统:CentOS7.5 Minimal

docker版本:18.06-ce

redis版本:6.0.6

二、安装docker

关闭selinux

setenforce 0

sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

下载docker二进制安装包

yum -y install wget

wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.0-ce.tgz

tar -zxf docker-18.06.0-ce.tgz

ll ./docker

cp ./docker/docker* /usr/bin

创建docker服务的unit文件

vim /etc/systemd/system/docker.service

##############################################################

Unit

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network-online.target firewalld.service

Wants=network-online.target

Service

Type=notify

the default is not to use systemd for cgroups because the delegate issues still

exists and systemd currently does not support the cgroup feature set required

for containers run by docker

ExecStart=/usr/bin/dockerd

ExecReload=/bin/kill -s HUP $MAINPID

Having non-zero Limit*s causes performance problems due to accounting overhead

in the kernel. We recommend using cgroups to do container-local accounting.

LimitNOFILE=infinity

LimitNPROC=infinity

LimitCORE=infinity

Uncomment TasksMax if your systemd version supports it.

Only systemd 226 and above support this version.

#TasksMax=infinity

TimeoutStartSec=0

set delegate yes so that systemd does not reset the cgroups of docker containers

Delegate=yes

kill only the docker process, not all processes in the cgroup

KillMode=process

restart the docker process if it exits prematurely

Restart=on-failure

StartLimitBurst=3

StartLimitInterval=60s

Install

WantedBy=multi-user.target

##############################################

启动docker服务,设置开机自启

systemctl daemon-reload

systemctl start docker

systemctl status docker

systemctl enable docker

docker info

docker version

设置镜像加速

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

systemctl restart docker

cat /etc/docker/daemon.json

# python -m json.tool /etc/docker/daemon.json

三、 拉取redis镜像,启动容器

docker pull redis

docker run -it --rm redis redis-cli -v

# docker tag redis:latest redis:6.0.6

docker run -it --rm redis cat /etc/passwd

mkdir /opt/redisdata

chown -R 999:999 /opt/redisdata

docker run -d --name redis -v /opt/redisdata:/data -p 6379:6379 redis:6.0.6 redis-server --appendonly yes

docker exec -it redis redis-cli config set requirepass "Redis@123"

docker logs redis

docker stop redis

docker rm redis

四、将redis注册成系统服务

vim /etc/systemd/system/redis.service

##################################################

Unit

Description=Redis Server

After=network-online.target docker.service

Requires=docker.service

Service

Type=simple

ExecStartPre=-/usr/bin/docker rm -f redis

ExecStart=/usr/bin/docker run \

--name redis \

-p 6379:6379 \

-v /opt/redisdata:/data \

redis:6.0.6 \

redis-server --appendonly yes --requirepass "Redis@123"

ExecStop=/usr/bin/docker stop redis

Restart=on-failure

StartLimitBurst=3

StartLimitInterval=60s

Install

WantedBy=multi-user.target

##################################################

systemctl daemon-reload

systemctl start redis

systemctl status redis

systemctl enable redis

docker exec -it redis redis-cli -a "Redis@123"

五、参考

使用 docker 快速部署 Redis

https://www.jianshu.com/p/67ce319d8782

docker安装redis设置密码并连接

http://www.apgblogs.com/docker-redis

Redis配置数据持久化---APPEND ONLY MODE

https://blog.csdn.net/ljl890705/article/details/51039015
最后编辑于:2025-04-21 10:37:32
© 著作权归作者所有,转载或内容合作请联系作者

喜欢的朋友记得点赞、收藏、关注哦!!!

相关推荐
-今昭-7 分钟前
AnsibleVault加密配置及zabbix部署
大数据·elasticsearch·搜索引擎
水无痕simon14 分钟前
6、六大工作模式-2
java·rabbitmq
2601_963870211 小时前
【计算机毕业设计】基于Spring Boot的非遗文创产品交易平台的设计与实现
java·spring boot·后端
lv__pf1 小时前
Spring之AOP底层源码解析(下)【TL spring14】
java·后端·spring
瑞通软件源头厂家1 小时前
酒店管理软件如何实现动态定价:功能解析与运作机制
大数据·创业创新
水无痕simon1 小时前
5、六大工作模式-1
java
KhalilRuan2 小时前
UnityCsReference——笔记
java·开发语言·笔记
OceanBase数据库官方博客2 小时前
OceanBase Harness Engineering?AI 产品真正的瓶(技术解析与实践)
大数据·人工智能·oceanbase
何以解忧,唯有..2 小时前
SpringBoot 中 @Transactional 注解失效的 8 种常见场景与解决方案
java
IT学长编程2 小时前
计算机毕业设计 基于用户评论主题挖掘的旅游景点推荐系统 Python 大数据毕业设计 Hadoop毕业设计选题【附源码+文档报告+安装调试】
大数据·python·django·毕业设计·数据可视化分析·旅游景点推荐系统·基于用户评论主题挖掘