无法在127.0.0.1:6379连接到Redis:在docker中拒绝连接(Could not connect to Redis at 127.0.0.1:6379: Connection refused in docker)
我正在使用redis-server:最新图片。 我用“docker run -it --name =”redis2“redis:1 bash”命令进入容器内部。 我看到默认情况下redis正在监听端口:6379。
Running in stand alone mode Port: 6379 PID: 39 http://redis.io [39] 01 Mar 09:03:45.669 # Server started, Redis version 2.8.4 [39] 01 Mar 09:03:45.669 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition.
要解决此问题,请将“vm.overcommit_memory = 1”添加到/etc/sysctl.conf,然后重新启动或运行命令“sysctl vm.overcommit_memory = 1”以使其生效。 [39] 01 Mar 09:03:45.669 *服务器现在已准备好接受端口6379上的连接
然后进一步没有回应。 我试过“redis-cli ping”。 没有回应。 然后我点击“ctrl + c”并键入“redis-cli ping”并获得以下响应:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
我尝试通过执行以下操作将端口更改为6001:
redis-server --port 6003
我看到以下回应:
Running in stand alone mode Port: 6003 PID: 47
我又尝试了“redis-cli ping”,它给我带来了同样的错误:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
我该如何解决? 我还在“/etc/redis/redis.conf”位置更新了端口(新端口6003)。
谢谢
I am using a redis-server:latest image. I used "docker run -it --name="redis2" redis:1 bash" command and got inside the container. I saw that by default redis is listening to Port: 6379.
Running in stand alone mode Port: 6379 PID: 39 http://redis.io [39] 01 Mar 09:03:45.669 # Server started, Redis version 2.8.4 [39] 01 Mar 09:03:45.669 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition.
To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. [39] 01 Mar 09:03:45.669 * The server is now ready to accept connections on port 6379
And then further there is no response. I tried "redis-cli ping". There was no response. Then I hit "ctrl+c" and type, "redis-cli ping" and get following response:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
I tried to change the port to 6001 by executing following:
redis-server --port 6003
And I see following response:
Running in stand alone mode Port: 6003 PID: 47
And again I tried "redis-cli ping" and it threw me the same error:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
How do I fix this? Also I have updated the port(the new port 6003) in "/etc/redis/redis.conf" location.
Thank you
原文:https://stackoverflow.com/questions/42529393
最满意答案
管道
|
是一个shell功能 。 如果你想使用它,你必须使用Popen withshell=True
。import subprocess p = subprocess.Popen(["ls | grep '20'"], stdout=subprocess.PIPE, shell=True) out, err = p.communicate() print out
注意:
警告如果与不受信任的输入结合使用,则传递shell = True可能会造成安全隐患。 有关详细信息,请参阅“常用参数”下的警告。
来源: subprocess.Popen
The pipe
|
is a shell feature. If you want to use it, you have to use Popen withshell=True
.import subprocess p = subprocess.Popen(["ls | grep '20'"], stdout=subprocess.PIPE, shell=True) out, err = p.communicate() print out
NOTE:
Warning Passing shell=True can be a security hazard if combined with untrusted input. See the warning under Frequently Used Arguments for details.
Source: subprocess.Popen
相关问答
更多-
你可以做: pipe = Popen(command_2, shell=True, stdin=PIPE, stdout=PIPE) pipe.stdin.write(result_1) pipe.communicate() 而不是管线。 You can do: pipe = Popen(command_2, shell=True, stdin=PIPE, stdout=PIPE) pipe.stdin.write(result_1) pipe.communicate() instead of the ...
-
来自文档 : communicate(self, input=None) Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional input argument should be a string to be sent to the c ...
-
管道| 是一个shell功能 。 如果你想使用它,你必须使用Popen with shell=True 。 import subprocess p = subprocess.Popen(["ls | grep '20'"], stdout=subprocess.PIPE, shell=True) out, err = p.communicate() print out 注意: 警告如果与不受信任的输入结合使用,则传递shell = True可能会造成安全隐患。 有关详细信息,请参阅“常用参数”下的警告。 ...
-
我认为这应该有效: p = subprocess.Popen( 'mailq |grep \"^[A-F0-9]\" |sort -k5n -k6n |head -n 1', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) response = ...
-
什么shell运行? 这在Python subprocess文档中提到: 可执行参数指定要执行的程序。 它很少需要:通常,要执行的程序由args参数定义。 如果shell = True,则可执行参数指定要使用的shell。 在Unix上,默认的shell是/bin/sh 。 在Windows上,默认shell由COMSPEC环境变量指定。 您需要在Windows上指定shell=True的唯一原因是您希望执行的命令实际内置于shell中,例如dir,copy。 您不需要shell = True来运行批处理文 ...
-
从文档中 , firebase init命令只创建文件firebase.json 。 为什么不以交互方式进行,然后再手动生成JSON呢? 即如果你这样做并且它产生了 { "firebase": "myfirebase", "public": "app", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ] } 那你就可以做到 $ echo $'{\n "firebase": "myfirebas ...
-
如果要通过其stdin将命令传递给子stdin=PIPE ,请设置stdin=PIPE : #!/usr/bin/env python from subprocess import Popen, PIPE proc = Popen('./Goldbackup -s -I -U'.split(), stdin=PIPE, stdout=PIPE, universal_newlines=True) output = proc.communicate('yes\n/dir/blabla ...
-
在同一个shell会话中没有理由运行这两个命令: print subprocess.check_output(["adb", "shell", "du -sh /sdcard/qpython"]) subprocess.check_output(["adb", "shell", "rm -r /sdcard/qpython"]) There is no reason for running both commands in the same shell session: print subprocess. ...
-
由于您的命令是管道,因此必须设置shell=True以便子进程将命令发送到shell: command = 'find /home/me/downloader/0-29/ -type f | grep -i .rpm$ | xargs -i cp {} /home/me/downloader/builds/0-29/' subprocess.call(command, shell=True) 要么, process = subprocess.Popen(command, shell=True) outpu ...
-
如何在Python 2.6中使用管道运行shell命令xargs(How to run shell command xargs with pipe in Python 2.6)[2021-12-12]
当使用shell = True时,Popen的第一个参数应该只是一个字符串而不是列表。 你也可以跑 subprocess.check_call("grep -lsr "somestring" ./somedir | xargs rm", shell=True) When using shell=True, the first argument to Popen should just be a string not a list. You could also just run subprocess.ch ...