创建一个redis docker容器
首先,我们先为redis创建一个Dockerfile文件和fix-permissions.sh文件
Dockerfile:
# "ported" by Adam Miller <[email protected]> from # https://github.com/fedora-cloud/Fedora-Dockerfiles # # Originally written for Fedora-Dockerfiles by # Aditya Patawari <[email protected]> FROM centos:centos7 MAINTAINER The CentOS Project <[email protected]> RUN yum -y update; yum clean all RUN yum -y install epel-release; yum clean all RUN yum -y install redis; yum clean all EXPOSE 6379 # log on stdout instead of writing to file RUN sed -i 's/^\(logfile\s*\).*$/\1""/g' /etc/redis.conf # Fix permissions to allow for running on openshift COPY fix-permissions.sh ./ RUN ./fix-permissions.sh /var/log/redis/ && \ ./fix-permissions.sh /var/lib/redis/ # By default will run as random user on openshift and the redis user (997) # everywhere else USER 997 ENTRYPOINT ["redis-server"] CMD ["/etc/redis.conf", "--bind", "0.0.0.0"]Dockerfile相关教程地址(官方GitHub地址) Dockerfile
fix-permissions.sh:(记得给文件加上执行权限(sudo chmod +x fix-permissions.sh))
<span style="font-size:18px;">#!/bin/sh # Taken from https://raw.githubusercontent.com/openshift/sti-base/master/bin/fix-permissions # Fix permissions on the given directory to allow group read/write of # regular files and execute of directories. chgrp -R 0 $1 chmod -R g+rw $1 find $1 -type d -exec chmod g+x {} +</span>
接着,构建镜像
<span style="font-size:18px;">docker build -t centos7/redis:centos7 .</span>查看镜像是否安装成功
到此,redis的镜像就已经安装成功了。
docker run -d -p 6379:6379 centos7/redis:centos7
docker run -d -p 6479:6479 centos7/redis:centos7
进入容器
先查询出Pid是什么:
docker inspect --format "{{ .State.Pid}}" <container-id>
nsenter --target 6537 --mount --uts --ipc --net --pid
直接通过输入:redis-cli就可以连上redis了。
[root@localhost ~]# docker inspect --format "{{ .State.Pid}}" e5a90a839f40 6537 [root@localhost ~]# nsenter --target 6537 --mount --uts --ipc --net --pid [root@e5a90a839f40 /]# redis-cli 127.0.0.1:6379>
安装就到这里了,怎么用,在下一篇博客再继续说!