[英]Redis in Docker container with custom redis.conf file not attaching
[英]IP's binding address in redis.conf within Linux Container
在 Ubuntu 20.04 中,我創建了一個名為“ubuntuone”的 Linux 容器,以及 Ubuntu 20.04。
在 Linux Container 中,我安裝了 Redis,但Could not connect to Redis at 127.0.0.1:6379
(base) raphy@pc:~$ lxc exec ubuntuone -- /bin/bash
root@ubuntuone:~# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
這是 linux 容器中ifconfig
的輸出:
(base) raphy@pc:~$ lxc exec ubuntuone -- /bin/bash
root@ubuntuone:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.65.116.195 netmask 255.255.255.0 broadcast 10.65.116.255
inet6 fe80::216:3eff:fe5b:de10 prefixlen 64 scopeid 0x20<link>
inet6 fd42:2159:3d69:bcae:216:3eff:fe5b:de10 prefixlen 64 scopeid
0x0<global>
ether 00:16:3e:5b:de:10 txqueuelen 1000 (Ethernet)
RX packets 2004 bytes 903491 (903.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2419 bytes 1053136 (1.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 8 bytes 496 (496.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 496 (496.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我也嘗試在/etc/redis/redis.conf
設置:
bind 10.65.116.195 ::1
但我得到了同樣的錯誤
更新 1)
安裝了 redis-server 但 redis-service.service 守護進程有一些問題:
root@ubuntuone:~# systemctl status redis-server.service
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service;
enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-07-28
08:41:03 UTC; 3min 54s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 2640 (code=exited, status=1/FAILURE)
Status: "Redis is loading..."
Jul 28 08:41:03 ubuntuone systemd[1]: Starting Advanced key-value
store...
Jul 28 08:41:03 ubuntuone systemd[1]: redis-server.service: Main
process exited, code=exited, status=1/FAILURE
Jul 28 08:41:03 ubuntuone systemd[1]: redis-server.service:
Failed with result 'exit-code'.
Jul 28 08:41:03 ubuntuone systemd[1]: Failed to start Advanced
key-value store.
root@ubuntuone:~# journalctl -xe
-- Subject: A start job for unit redis-server.service has begun
execution
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit redis-server.service has begun execution.
--
-- The job identifier is 2538.
Jul 28 08:41:03 ubuntuone systemd[1]: redis-server.service: Main
process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStart= process belonging to unit redis-server.service
has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Jul 28 08:41:03 ubuntuone systemd[1]: redis-server.service:
Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit redis-server.service has entered the 'failed' state
with result 'exit-code'.
Jul 28 08:41:03 ubuntuone systemd[1]: Failed to start Advanced
key-value store.
-- Subject: A start job for unit redis-server.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit redis-server.service has finished with a
failure.
--
-- The job identifier is 2538 and the job result is failed.
Jul 28 08:44:39 ubuntuone systemd[1]: Reloading.
Jul 28 08:44:39 ubuntuone systemd[1]: systemd-udevd.service:
Attaching egress BPF program to cgroup /sys/fs/cgro>
Jul 28 08:44:39 ubuntuone systemd[1]: systemd-journald.service:
Attaching egress BPF program to cgroup /sys/fs/c>
Jul 28 08:44:39 ubuntuone systemd[1]: systemd-logind.service:
Attaching egress BPF program to cgroup /sys/fs/cgr>
如何解決問題?
看了你的評論,看來Redis服務只是安裝了沒有啟動。 您可以使用redis-server
二進制文件啟動它。 啟動后就可以連接了。
此外,您不需要在 Ubuntu 容器內安裝 redis 服務器。 已經在 Debian 或其他 SO 上預先構建了 redis 映像。 請檢查Redis Docker Hub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.