小滴课堂 - docker笔记10 - Dockerfile构建redis镜像

1.dockerfile文件内容
文件目录结构:

[root@iZbp1e9mxelwe7pwimpw8sZ local]# ls
aegis  apache-activemq-5.15.12  bin  etc  games  include  jdk8  lib  lib64  libexec  mq_dockfile  nginx  redis-4.0.9  redis-4.0.9.tar.gz  redis_dockerfile  redis_install.sh  sbin  share  soft  src  tomcat8
[root@iZbp1e9mxelwe7pwimpw8sZ local]# 

安装redis的shell脚本:

#!/bin/bash
yum install -y gcc gcc-c++ make openssl openssl-devel
cd /usr/local/redis-4.0.9
make && make PREFIX=/usr/local/redis-4.0.9 install
sed -i '69s/127.0.0.1/0.0.0.0/' /usr/local/redis-4.0.9/redis.conf
sed -i '88s/protected-mode yes/protected-mode no/' /usr/local/redis-4.0.9/redis.conf

构建redis镜像的dockerfile文件内容

FROM centos:7
EXPOSE 6379
ENV LANG C.UTF-8
ADD redis-4.0.9.tar.gz /usr/local/
COPY redis_install.sh /usr/local/
RUN sh /usr/local/redis_install.sh
ENTRYPOINT /usr/local/redis-4.0.9/bin/redis-server /usr/local/redis-4.0.9/redis.conf

2.构建redis镜像
命令
docker build -f redis_dockerfile -t redis:4 .

构建redis镜像完毕

[root@iZbp1e9mxelwe7pwimpw8sZ local]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               4                   26672d825c28        8 minutes ago       468MB
nginx               1.6                 5001dfcbffca        3 days ago          393MB
tomcat              8                   1b84c8c44909        8 days ago          1.04GB
jenkins/jenkins     lts                 5307ff34e221        4 weeks ago         648MB
jekins              lastest             5307ff34e221        4 weeks ago         648MB
centos              7                   5e35e350aded        6 months ago        203MB
[root@iZbp1e9mxelwe7pwimpw8sZ local]# 

3.运行redis容器

命令
docker run -itd -p 6379:6379 --name=redis4 redis:4

运行容器的结果

[root@iZbp1e9mxelwe7pwimpw8sZ local]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
0866a39c59a8        redis:4             "/bin/sh -c '/usr/lo…"   11 minutes ago      Up 11 minutes       0.0.0.0:6379->6379/tcp   redis4
[root@iZbp1e9mxelwe7pwimpw8sZ local]# 

4.测试结果
连接redis desktop manager并设置一个值
在这里插入图片描述

进入redis的docker容器
命令
docker exec -itd redis4 /bin/bash

运行redis客户端,并查看设置的值

[root@0866a39c59a8 bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server
[root@0866a39c59a8 bin]# ./redis-cli 
127.0.0.1:6379> get a
"a"
127.0.0.1:6379> 

5.文章参考链接
a. https://xdclass.net/#/index

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读