Redis在 some-redis:6379 上:名称或服务未知。

huangapple go评论53阅读模式
英文:

Redis at some-redis:6379: Name or service not known

问题

我正在使用Windows 10 Enterprise上的Hyper-V运行Docker,尝试使用官方最新的Redis镜像创建Redis容器。我遵循了Docker网站上的说明(https://www.docker.com/blog/how-to-use-the-redis-docker-official-image/),但遇到了以下错误:

Redis at some-redis:6379: Name or service not known

我觉得我可能漏掉了一些东西,但不确定为什么,因为这是文档上写的,但也许只是一个设置的一般概念?此外,没有Dockerfile,所以也许这个东西也是缺失的。

也许网络命令有问题:

docker network create some-network
docker run -it --network some-network --rm redis redis-cli -h some-redis

难道不应该是一个桥接网络,并且应该有一个包含这些设置的Dockerfile吗?

英文:

I am running Docker with Hyper-V on Windows 10 Enterprise and attempting to create a Redis container using the official latest Redis image. I followed the instructions on the Docker website (https://www.docker.com/blog/how-to-use-the-redis-docker-official-image/) but I am encountering the following error:

Redis at some-redis:6379: Name or service not known

I do feel like I'm missing something, but not sure why as this is what the documentations say, but maybe it was just a general idea of how to set it up? Also, there is no Dockerfile so maybe that's missing.

Maybe the network commands are wrong:

docker network create some-network
​​docker run -it --network some-network --rm redis redis-cli -h some-redis

Shouldn't it be a bridged network, and shouldn't there be a Dockerfile with these settings in it?

答案1

得分: 1

创建的容器需要保持在同一个Docker网络中,以便能够进行通信。

在您的情况下,首先创建网络:

docker network create some-network

然后创建redis-server,指定网络(刚刚创建的)和要暴露的端口:

docker run --name some-redis --network some-network -p 6379:6379 -d redis redis-server --save 60 1 --loglevel warning

最后,在与6379端口绑定的同一网络上启动cli:

docker run -it --network some-network --rm redis redis-cli -h some-redis
英文:

The containers you create need to stay in the same Docker network in order to be able to communicate.

In your case, first create the network:

docker network create some-network

then create the redis-server, with the specification of the network (just created) and port to expose:

docker run --name some-redis --network some-network -p 6379:6379 -d redis redis-server --save 60 1 --loglevel warning

finally, start the cli on the same network that will bind to the 6379 port:

docker run -it --network some-network --rm redis redis-cli -h some-redis

huangapple
  • 本文由 发表于 2023年6月16日 04:51:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485434.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定