標籤:redis docker server
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之後,關掉putty7.重新進入putty8.為了測試方便直接在本機裝個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.
Docker中的Redis容器如何串連上進行操作?