在我的 MBP 上,安装了最新的 boot2docker
,我有以下 Dockerfile
:
FROM redis:3.0.3
CMD redis-server --bind 0.0.0.0
我运行以下命令:
docker build .
docker run --rm ba09b207db42 # where ba09b207db42 is the container id returned by the build command
然后我运行:
redis-cli -h `boot2docker ip`
我得到了错误:
Could not connect to Redis at 192.168.59.103:6379: Connection refused
我错过了什么?
最佳答案
您忘记公开端口。只需像这样运行容器:
docker run --rm -p 6379:6379 ba09b207db42
另外:
您可以为图像命名,这样就无需使用 id:
docker build -t myimage .
然后您可以在后台启动容器,这样它就不会“阻塞”您的终端:
docker run --name mycontainer -d -p 6379:6379 myimage
关于redis - 无法使用 boot2docker 连接到作为容器运行的 redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31889163/