程序员人生 网站导航

Docker中的Redis容器如何连接上进行操作?

栏目:服务器时间:2015-01-15 08:33:54

Docker中的Redis容器如何连接上进行操作?

1.登录putty有以下信息:

公用虚拟 IP (VIP)地址
42.159.156.115
内部 IP 地址
10.205.178.22
IP address for eth0:    10.205.178.22
IP address for docker0: 172.17.42.1


2. 下载 http://download.redis.io/redis-stable/redis.conf修改以下字段

# requirepass foobared去掉注释,foobared改成自己的密码password

3.改好后传到 https://www.sendspace.com/

Download Link
https://www.sendspace.com/file/p1j6ac
Copy Link
Delete File Link
https://www.sendspace.com/delete/p1j6ac/9e70e7f78a89601d5658ccbdc4834c43

点击"Download Link"下方的连接,新页面复制“Click here to start download from sendspace:”的链接:https://fs10n2.sendspace.com/dl/03acafeeb8a1b799798666d55267a9cd/54a419057626bfac/p1j6ac/redis.conf(注意不要点击!如果点击请重新刷新页面,每次下载完都会变化)

4.运行映照的Redis

sudo docker run -t -i -p 172.17.42.1:6379:6379 redis:latest /bin/bash

注意:这里的IP地址是docker的IP地址


5. 下载conf文件,运行Redis-Server

cd /usr/local/bin
curl -o redis.conf https://fs10n2.sendspace.com/dl/03acafeeb8a1b799798666d55267a9cd/54a419057626bfac/p1j6ac/redis.conf
Note: 如果出现括号内的毛病多试几次(Try more times if meet:curl: (6) Couldn't resolve host 'fs10n3.sendspace.com')

redis-server redis.conf

6.启动Redis-server以后,关掉putty

7.重新进入putty

8.为了测试方便直接在本机装个Redis-server:

apt-get install redis-server

9.进入容器,设置下值:

sudo docker ps -l

docker-enter 4fb1f04d706c

redis-cli -a password

set myvalue valueindocker

按Ctrl+D退出docker容器

10.在本机连接上docker里的redis-server;

redis-cli -h 172.17.42.1 -a password

get myvalue

"valueindocker"

11.另外关于公网如何访问docker,正在尝试:

iptables -t nat -A PREROUTING -m tcp -p tcp --dport 12345 -j DNAT --to-destination 172.17.42.1:6379
iptables -t nat -A POSTROUTING  -m tcp -p tcp --dport 12345 -d 172.17.42.1 -j SNAT --to-source 42.159.156.115
iptables -A INPUT -p tcp --dport 12345 -j ACCEPT

有新进展会通知继续发新文章,谢谢!



5. 
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐