赞
踩
1.创建文件夹redis
mkdir redis
cd redis
创建三个目录
mkdir shell #构建、启动、停止等脚本
mkdir dockerfile #dockerfile目录
mkdir volumes #挂载配置、日志、数据文件
2.准备redis包、dockerfile文件
cd dockerfile/
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
ll
编写dokcerfile文件
vim Dockerfile
FROM centos:7.7.1908
ADD redis-5.0.3.tar.gz /home
# 创建者
MAINTAINER mfw
run yum install -y wget install make gcc libgcc gcc-c++ glibc-devel make && mkdir -p /docker/redis/{install,conf,data,log} && mv /home/redis-5.0.3 /docker/redis/install/ && cd /docker/redis/install/redis-5.0.3 && make && make install PREFIX=/docker/redis/ && useradd hd && chown -R hd:hd /docker/redis && rm -rf /docker/redis/install/*.gz
USER hd
EXPOSE 6379
CMD ["/docker/redis/bin/redis-server","/docker/redis/conf/6379.conf"]
3.构建镜像
dockerfile目录下执行
docker build -t redis:v1 .
4.编写生成容器脚本
cd ../shell/
vim run
#!/bin/sh
DOCKER_PATH=$PWD/../
port=6379
version=v1
imageName=redis
docker run -d -p ${port}:6379 --name redis -v /etc/localtime:/etc/localtime -v $DOCKER_PATH/volumes/conf:/docker/redis/conf -v $DOCKER_PATH/volumes/data/:/docker/redis/data/ -v $DOCKER_PATH/volumes/log:/docker/redis/log --restart=unless-stopped ${imageName}:${version} /docker/redis/bin/redis-server /docker/redis/conf/${port}.conf
5.准备配置文件
cd ../volumes
mkdir config
vim 6379.conf
6.创建容器
cd ../shell/
./run
7.测试
redis-cli
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。