1. 创建并启动镜像(我的镜像名字叫做:mycentos-redis:1.0)

docker run -i -t -p mycentos-redis:1.0 /bin/bash

2. 进入到镜像的命令行,下载redis,并且编译redis,此处不再说明。看我的redis系列博客文章。

3. 退出镜像(这时镜像已停止运行),回到宿主机,通过命令再次启动镜像

docker start e60da5191243

4. 使用命令查看镜像的ip地址:docker inspect e60da5191243|grep -i add

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
# When protected mode is on and if:
# 1) The server is not binding explicitly to a set of addresses using the
"redis.conf" 1052L, 46696C written
            "LinkLocalIPv6Address": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "GlobalIPv6Address": "",
            "IPAddress": "",
            "MacAddress": "02:42:ac:11:00:02",
                    "IPAddress": "",
                    "GlobalIPv6Address": "",
                    "MacAddress": "02:42:ac:11:00:02"


5. 通过命令再次进去到镜像(通过exec进入镜像再退出,容器还是会继续执行。看我另一篇博客关于docker run和exec命令的区别)

docker exec -i -t e60da5191243 /bin/bash

6. 在镜像中,编辑redis的配置文件,修改bind地址为:,默认端口是6379,保存退出,并启动redis-server

7. 由于在创建该镜像时已经通过宿主的56379端口映射到6379端口,所以此时已经可以访问到镜像中的redis-server了

redis-cli -h -p 56379













欢迎交流问题,可加个人QQ 469580884,

或者,加我的群号 751925591,一起探讨交流问题


Talk is cheap,show me the code


已标记关键词 清除标记
<div class="post-text" itemprop="text"> <p>I have a docker-compose file with several containers in, two of which are supposed to communicate via a Redis DB. Both containers have connections to Reids and I can read/write from both. However I'd like a container to be triggered every time the something is added from the other container. I thought I could accomplish this via Redis Sub/Pub but it when I run the code it never triggers anything, even when I can see I've added new items to the Redis queue. </p> <p>From this I have two questions: 1. Is what I'm looking to do even possible? Can I do publish/subscribe in in two separate docker containers and expect it work as described above? 2. If it is possible, can someone please point me below where I"m going wrong with this tools? </p> <p>This is my function that I add new data to the Redis queue and then publish the data in Docker container 1. </p> <pre><code>func redisShare(key string, value string) { jobsQueue.Set(key, value, 0) //setting in the queue jobsQueue.Publish(key, value) //publishing for the other docker container to notice fmt.Println("added ", key, "with a value of ", value, "to the redis queue") } </code></pre> <p>I'm using this line in my other docker container to subscribe to the Redis queue and listen for changes: <code>redisdb.Subscribe()</code></p> <p>I would expect if something was added to the redis queue it would share the data to the other container and I'd see the message received, but right now Docker Container 2 just runs and then closes. </p> <p>Thanks! </p> </div>
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页