本文源链接地址:https://www.93bok.com
1、下载基础镜像centos
docker pull centos:6
2、查看一下大小
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 6 70b5d81549ec 2 months ago 195MB
3、创建文件夹存放Redis的Dockerfile,以及源码包等等,为后期docker-compose做准备
mkdir -p /data/docker/lnmp-test/dockerfile/redis
4、创建Redis的Dockerfile
vim /data/docker/lnmp-test/dockerfile/redis/Dockerfile
FROM centos:6
LABEL maintainer="[email protected]" description="Redis image"
COPY redis-3.0.2.tar.gz /root/redis-3.0.2.tar.gz
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 && yum -y install gcc && tar -zxvf /root/redis-3.0.2.tar.gz -C /root/ && cd /root/redis-3.0.2 && make PREFIX=/usr/local/redis install && ln -s /usr/local/redis/bin/* /usr/local/bin/ && mkdir -p /etc/redis && mkdir -p /data/redis && mkdir -p /data/log && cp /root/redis-3.0.2/redis.conf /etc/redis/ && sed -i ‘s#logfile ""#logfile /data/log/redis.log#‘ /etc/redis/redis.conf && sed -i ‘s#dir ./#dir /data/redis#‘ /etc/redis/redis.conf && sed -i ‘s#appendonly no#appendonly yes#‘ /etc/redis/redis.conf && rm -rf /root/redis* && yum clean all
EXPOSE 6379
CMD ["redis-server","/etc/redis/redis.conf"]
5、把redis源码包上传到/data/docker/lnmp-test/dockerfile/redis/目录下
6、创建镜像
cd /data/docker/lnmp-test/dockerfile/redis/
docker build -t centos6:redis .
7、查看镜像大小
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6 redis f06d5e0b0a71 4 seconds ago 395MB
centos 6 70b5d81549ec 3 months ago 195MB
8、启动容器测试是否成功
docker run -d -p 6379:6379 --name redis centos6:redis
9、宿主机开启防火墙6379端口
firewall-cmd --add-port=6379/tcp --permanent
systemctl restart firewalld
原文地址:https://www.cnblogs.com/93bok/p/9684835.html
时间: 2024-10-14 17:03:22