无法使用 boot2docker 连接到 redis 运行 作为容器
Cannot connect to redis running as container with boot2docker
在我的 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 .
然后您可以在后台启动容器,这样它就不会 "block" 您的终端:docker run --name mycontainer -d -p 6379:6379 myimage
在我的 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 .
然后您可以在后台启动容器,这样它就不会 "block" 您的终端:
docker run --name mycontainer -d -p 6379:6379 myimage