此问题已在此处找到答案:
docker中“公开”和“发布”的区别是什么((6个答案)
两天前关门了。
按照url链接中的建议在本地运行redis docker映像,从日志中可以看出运行良好
docker pull redis
docker run --name some-redis -d redis
然后docker开始了。我可以看到下面的日志
docker logs --follow some-redis
1:C 08 Jul 2021 07:17:51.243 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 08 Jul 2021 07:17:51.243 # Redis version=6.2.4, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 08 Jul 2021 07:17:51.243 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 08 Jul 2021 07:17:51.244 * monotonic clock: POSIX clock_gettime
1:M 08 Jul 2021 07:17:51.247 * Running mode=standalone, port=6379.
1:M 08 Jul 2021 07:17:51.248 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 08 Jul 2021 07:17:51.248 # Server initialized
1:M 08 Jul 2021 07:17:51.250 * Ready to accept connections
我用绝地武士连接到这个redis容器这里这个代码和redis docker都在本地机器上。下面的代码不在容器上,而是在本地主机上。redis已经公开了6379端口redis dockerfile链接
public static void main(String [] args) {
System.out.println("connecting");
Jedis jedis;
jedis = new Jedis("localhost",6379);
System.out.println("connected and pinging now");
//jedis.ping();
jedis.set("events/city/rome", "32,15,223,828"); //line 274
String cachedResponse = jedis.get("events/city/rome");
System.out.println("ping done");
}
我在连接时出错
connecting
connected and pinging now
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
at redis.clients.jedis.Connection.connect(Connection.java:164)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:80)
at redis.clients.jedis.Connection.sendCommand(Connection.java:100)
at redis.clients.jedis.BinaryClient.set(BinaryClient.java:97)
at redis.clients.jedis.Client.set(Client.java:32)
at redis.clients.jedis.Jedis.set(Jedis.java:68)
at com.org.app.module.TaskPerformer.main(TaskPerformer.java:274)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:606)
at redis.clients.jedis.Connection.connect(Connection.java:158)
... 6 more
此错误发生在第273行 jedis.ping()
也
1条答案
按热度按时间ulydmbyx1#
您应该将redis端口(tcp 6379)发布到主机系统,或者明确提及该端口,或者使用主机网络。
以下是如何仅发布tcp端口6379(推荐解决方案):
以下是您如何通过使用网络主机来实现这一点(对于您的简单案例来说,这似乎是一种过度的做法,可能会暴露出进一步的安全风险):