Docker 使用Dockerfile构建redis镜像

Dockerfile实现:

FROM centos:7.2.1511
MAINTAINER hongdada "[email protected]"

WORKDIR /home

RUN yum install -y wget gcc && \      
        rpm --rebuilddb && \
        yum -y install gcc automake autoconf libtool make && \
        yum -y install net-tools && \
        yum -y install tar && \
        wget http://download.redis.io/redis-stable.tar.gz && \
        tar -xvzf redis-stable.tar.gz && \
        mv redis-stable/ redis && \
        rm -f redis-stable.tar.gz && \
        yum clean all && \
        cd redis && \
        make && make install
        
EXPOSE 6379

ENTRYPOINT redis-server /home/redis/redis.conf

CMD ["redis-server"]

因为有make命令

所以要

yum -y install gcc automake autoconf libtool make 

想要查看ifconfig,所以安装net-tools

 yum -y install net-tools

利用这个Dockerfile构建镜像命令:

[root@localhost tomcat]# docker build -t redis:v3 .

启动容器: 

[root@localhost redis]# docker run -d -p 6366:6379 redis:v3
84ea1a89ef010f61d2fb58f05979691f6cfbd5123399c90cd46c5cc56788e177

查看容器:

[root@localhost redis]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
84ea1a89ef01        redis:v3            "/bin/sh -c 'redis..."   4 seconds ago       Up 3 seconds        0.0.0.0:6366->6379/tcp   agitated_chandrasekhar
b445ecc8eb60        centos:v1           "/bin/sh -c '/home..."   3 hours ago         Up 3 hours          0.0.0.0:8088->8080/tcp   suspicious_bassi

进入容器内部:

[root@localhost /]# docker exec -it 84 /bin/bash

对redis进行操作:

[root@84ea1a89ef01 redis]# redis-cli
127.0.0.1:6379> set name hongdada
OK
127.0.0.1:6379> set age 22
OK
127.0.0.1:6379> keys *
1) "age"
2) "name"
3) "key"
127.0.0.1:6379> 

 

可能出现的问题:

如果centos更换版本或者 取消yum install gcc,可能会出现-bash: make: command not found提示,

是因为安装系统的时候使用的是最小化mini安装,系统没有安装make、vim等常用命令,直接yum安装下即可。

yum -y install gcc automake autoconf libtool make

参考:

https://blog.csdn.net/chenyufeng1991/article/details/78766062

http://dockone.io/article/1130

转载于:https://www.cnblogs.com/hongdada/p/9268865.html

你可能感兴趣的:(数据库,运维,网络)