接着上一篇文章继续操作
查看容器
[river@bogon ~]$ sudo docker ps
[sudo] password for river:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
de749d8aff6c river/centos-1 "init" 17 minutes ago Up 17 minutes 0.0.0.0:3306->3306/tcp epic_khayyam
进入容器
[river@bogon ~]$ sudo docker exec -it de749d8aff6c bash
[root@de749d8aff6c /]# su river
[river@de749d8aff6c /]$
在CentOS和Red Hat系统中,首先添加EPEL仓库,然后更新yum源:
sudo yum install epel-release
sudo yum update
然后安装Redis数据库:
sudo yum -y install redis
安装好后启动Redis服务即可:
[river@de749d8aff6c /]$ sudo systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
[river@de749d8aff6c /]$ sudo systemctl start redis
[river@de749d8aff6c /]$ sudo systemctl status redis
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: active (running) since Fri 2019-04-26 15:01:05 UTC; 6s ago
Main PID: 2867 (redis-server)
CGroup: /docker/de749d8aff6cba86262562d8e900329bf6f055d81b4362e5a491880cdc20047c/docker/de749d8aff6cba86262562d8e900329bf6f055d81b4362e5a491880cdc20047c/system.slice/redis.service
└─2867 /usr/bin/redis-server 127.0.0.1:6379
‣ 2867 /usr/bin/redis-server 127.0.0.1:6379
Apr 26 15:01:05 de749d8aff6c systemd[1]: Starting Redis persistent key-value database...
Apr 26 15:01:05 de749d8aff6c systemd[1]: Started Redis persistent key-value database.
[river@de749d8aff6c /]$
配置Redis能被远程连接
vi /etc/redis.conf
需要修改的地方:
改绑定地址:
bind 0.0.0.0
注释掉发现没起作用(#bind 127.0.0.1)
保存镜像
[river@bogon ~]$ sudo docker commit -m="has mysql" -a="river" de749d8aff6c river/centos-2
[sudo] password for river:
sha256:e17a41ef44dcee0e06a99da36b146fbcdcf52bd573a50cbbde1780d6c06ea3dc
重启
[river@bogon ~]$ sudo docker run -itd --privileged=true -p 3306:3306 -p 6379:6379 river/centos-2 init
0831e1d395ffeba63b935838845d022456ba9af79c69502681394c09538bf6f8
[river@bogon ~]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0831e1d395ff river/centos-2 "init" 10 seconds ago Up 9 seconds 0.0.0.0:3306->3306/tcp, 0.0.0.0:6379->6379/tcp trusting_wilbur
22ed961ea11f river/centos "init" About an hour ago Up About an hour hardcore_wing
2bebc88809f6 river/centos "/bin/bash" About an hour ago Up About an hour modest_sammet
255b799c5285 daocloud.io/centos:7 "/bin/bash" 2 hours ago Up 2 hours
网友评论