选择基镜像
基镜像使用dokcer hub官方提供的redis,https://hub.docker.com/_/redis/
docker pull redis:4.0.10-alpine
docker tag redis:4.0.10-alpine 10.240.4.159/app/redis
docker push 10.240.4.159/app/redis
|
制作带SSH镜像
mkdir /root/docker_build/redis-ssh
cd /root/docker_build/redis-ssh
cp /usr/share/zoneinfo/Asia/Shanghai .
vi repositories
http://mirrors.aliyun.com/alpine/v3.7/main
http://mirrors.aliyun.com/alpine/v3.7/community
vi docker-entrypoint.sh
/usr/sbin/sshd -D &
set -e
if [ "${1#-}" != "$1" ] || [ "${1%.conf}" != "$1" ]; then
set -- redis-server "$@"
fi
if [ "$1" = 'redis-server' -a "$(id -u)" = '0' ]; then
chown -R redis .
exec su-exec redis "$0" "$@"
fi
exec "$@"
vi Dockerfile
FROM 10.240.4.159/app/redis:4.0.10-alpine
ADD Shanghai /etc/localtime
ADD repositories /etc/apk/repositories
RUN apk --no-cache update
RUN apk --no-cache add openssh
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" \
&& ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N "" \
&& ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N "" \
&& ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" \
&& sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config \
&& echo 'root:ydgw.cn' | chpasswd
RUN echo '' > /etc/redis.conf \
&& chown redis:redis /etc/redis.conf \
&& chmod 640 /etc/redis.conf
ADD docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD [ "redis-server", "/etc/redis.conf" ]
docker build -t 10.240.4.159/app/redis:4.0.10-alpine-ssh .
docker push 10.240.4.159/app/redis:4.0.10-alpine-ssh
|
创建VOLUME卷
mkdir -p /docker_mnt/redis/data
cp redis.conf /docker_mnt/redis/
|
部署REDIS服务
- 登陆Rancher(1.6.18),编排工具用的是默认的Cattle
- 应用 - 用户 - 添加应用 - 名称:[REDIS] - 创建
- 添加服务 - 在添加服务页面添写配置如下信息 - 创建
名称: redis
选择镜像: 10.240.4.159/app/redis:4.0.10-alpine-ssh
端口映射: 6379:6379/tcp 15921:22/tcp
卷 - 添加卷: /docker_mnt/redis/data:/data
/docker_mnt/redis/redis.conf:/etc/redis.conf
网络 - 主机名: redis
调度 - 在指定主机上运行全部容器: docker159
|