账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    docker compose 创建的 redis container 无法远程访问
    10
    0
    最近在测试环境用 docker-compse 创建了一个 redis 容器,结果远程无法访问;但是手动(docker命令)创建的就没问题(使用 redis 客户端连接测试过),感觉见鬼了,下面是 docker-compose.yaml:version: '3'services: redis: image: redis container_name: t_redis privileged: true volumes: - /home/opensearch/redis/data:/data - /home/opensearch/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf - ./logs/redis-server.log:/usr/local/etc/redis/logs/redis-server.log command: redis-server /usr/local/etc/redis/redis.conf --save 60 1 ports: - 6379:6379创建完之后的效果:[root@localhost redis]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4585b293e57a redis "docker-entrypoint..." 2 minutes ago Up 2 minutes 0.0.0.0:6379->6379/tcp t_redisd2e2bd273f83 redis "docker-entrypoint..." 2 hours ago Up 2 hours 0.0.0.0:6380->6379/tcp mrd(其中 mrd 是手动创建的,t_redis 是 docker-compose 创建的)下面是 docker inspect t_redis的结果:[ { "Id": "4585b293e57a6543edb20a67858f787415c3f3eb0eade00c66aee459b5a75e1f", "Created": "2021-11-23T00:40:03.551490088Z", "Path": "docker-entrypoint.sh", "Args": [ "redis-server", "/usr/local/etc/redis/redis.conf", "--save", "60", "1" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 5742, "ExitCode": 0, "Error": "", "StartedAt": "2021-11-23T00:40:03.858021926Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:7faaec68323851b2265bddb239bd9476c7d4e4335e9fd88cbfcc1df374dded2f", "ResolvConfPath": "/var/lib/docker/containers/4585b293e57a6543edb20a67858f787415c3f3eb0eade00c66aee459b5a75e1f/resolv.conf", "HostnamePath": "/var/lib/docker/containers/4585b293e57a6543edb20a67858f787415c3f3eb0eade00c66aee459b5a75e1f/hostname", "HostsPath": "/var/lib/docker/containers/4585b293e57a6543edb20a67858f787415c3f3eb0eade00c66aee459b5a75e1f/hosts", "LogPath": "", "Name": "/t_redis", "RestartCount": 0, "Driver": "overlay2", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": [ "/home/opensearch/redis/data:/data:rw", "/home/opensearch/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf:rw", "/home/opensearch/redis/logs/redis-server.log:/usr/local/etc/redis/logs/redis-server.log:rw" ], "ContainerIDFile": "", "LogConfig": { "Type": "journald", "Config": {} }, "NetworkMode": "redis_default", "PortBindings": { "6379/tcp": [ { "HostIp": "", "HostPort": "6379" } ] }, "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "Dns": null, "DnsOptions": null, "DnsSearch": null, "ExtraHosts": null, "GroupAdd": null, "IpcMode": "", "Cgroup": "", "Links": null, "OomScoreAdj": 0, "PidMode": "", "Privileged": true, "PublishAllPorts": false, "ReadonlyRootfs": false, "SecurityOpt": [ "label=disable" ], "UTSMode": "", "UsernsMode": "", "ShmSize": 67108864, "Runtime": "docker-runc", "ConsoleSize": [ 0, 0 ], "Isolation": "", "CpuShares": 0, "Memory": 0, "NanoCpus": 0, "CgroupParent": "", "BlkioWeight": 0, "BlkioWeightDevice": null, "BlkioDeviceReadBps": null, "BlkioDeviceWriteBps": null, "BlkioDeviceReadIOps": null, "BlkioDeviceWriteIOps": null, "CpuPeriod": 0, "CpuQuota": 0, "CpuRealtimePeriod": 0, "CpuRealtimeRuntime": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": null, "DiskQuota": 0, "KernelMemory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": -1, "OomKillDisable": false, "PidsLimit": 0, "Ulimits": null, "CpuCount": 0, "CpuPercent": 0, "IOMaximumIOps": 0, "IOMaximumBandwidth": 0 }, "GraphDriver": { "Name": "overlay2", "Data": { "LowerDir": "/var/lib/docker/overlay2/f130cf237e12fa1d29f8624cb53b4c209080d38278c3b463d36e6b010f583623-init/diff:/var/lib/docker/overlay2/e0e66fa382b2683a452e4f0eb077c3dd03010a79725f2ed271af5bd238748abc/diff:/var/lib/docker/overlay2/8b33dbe58f10653d01038943c872b9ef165dceb6af53ce304166c901550d51bd/diff:/var/lib/docker/overlay2/729b5e1575c94873ca0ca032797b0f8243a3d653b5aa3aa59d2f14cf367ad542/diff:/var/lib/docker/overlay2/910b569c9b4de2ac85f8ba05cf8ce14b712d8bbe5a119d9538d370d448bf20c8/diff:/var/lib/docker/overlay2/e0be5b91fb38f4ceebaf73056c06bdd332d166d21a1e29d92ca3aa236b250b6b/diff:/var/lib/docker/overlay2/5ae06b8381c7129ecdfbbeae6a31771c375dce0cc15a7edc81ebb0358d32f590/diff", "MergedDir": "/var/lib/docker/overlay2/f130cf237e12fa1d29f8624cb53b4c209080d38278c3b463d36e6b010f583623/merged", "UpperDir": "/var/lib/docker/overlay2/f130cf237e12fa1d29f8624cb53b4c209080d38278c3b463d36e6b010f583623/diff", "WorkDir": "/var/lib/docker/overlay2/f130cf237e12fa1d29f8624cb53b4c209080d38278c3b463d36e6b010f583623/work" } }, "Mounts": [ { "Type": "bind", "Source": "/home/opensearch/redis/data", "Destination": "/data", "Mode": "rw", "RW": true, "Propagation": "rprivate" }, { "Type": "bind", "Source": "/home/opensearch/redis/conf/redis.conf", "Destination": "/usr/local/etc/redis/redis.conf", "Mode": "rw", "RW": true, "Propagation": "rprivate" }, { "Type": "bind", "Source": "/home/opensearch/redis/logs/redis-server.log", "Destination": "/usr/local/etc/redis/logs/redis-server.log", "Mode": "rw", "RW": true, "Propagation": "rprivate" } ], "Config": { "Hostname": "4585b293e57a", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "ExposedPorts": { "6379/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "GOSU_VERSION=1.12", "REDIS_VERSION=6.2.6", "REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-6.2.6.tar.gz", "REDIS_DOWNLOAD_SHA=5b2b8b7a50111ef395bf1c1d5be11e6e167ac018125055daa8b5c2317ae131ab" ], "Cmd": [ "redis-server", "/usr/local/etc/redis/redis.conf", "--save", "60", "1" ], "Image": "redis", "Volumes": { "/data": {}, "/usr/local/etc/redis/logs/redis-server.log": {}, "/usr/local/etc/redis/redis.conf": {} }, "WorkingDir": "/data", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": { "com.docker.compose.config-hash": "f3319b0b292d5e0441f7f7019ce7efce1c8b2f69f1c261258fa3023deeccd6d7", "com.docker.compose.container-number": "1", "com.docker.compose.depends_on": "", "com.docker.compose.image": "sha256:7faaec68323851b2265bddb239bd9476c7d4e4335e9fd88cbfcc1df374dded2f", "com.docker.compose.oneoff": "False", "com.docker.compose.project": "redis", "com.docker.compose.project.config_files": "/home/opensearch/redis/docker-compose.yaml", "com.docker.compose.project.working_dir": "/home/opensearch/redis", "com.docker.compose.service": "redis", "com.docker.compose.version": "2.1.0" } }, "NetworkSettings": { "Bridge": "", "SandboxID": "c18bbfc1a2a7616ad1e1a994c7e9981f4f34caa6e12d6f0b87a4e5d592b5007e", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": { "6379/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "6379" } ] }, "SandboxKey": "/var/run/docker/netns/c18bbfc1a2a7", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "redis_default": { "IPAMConfig": null, "Links": null, "Aliases": [ "t_redis", "redis", "4585b293e57a" ], "NetworkID": "bc42862ddf24cba78ef8a57f888d014dc2dc0375b00bebc10ab500872c2e16a6", "EndpointID": "6b6e4a8792b1513c0036869b860b287991156735dc45f92f9770bf2dc5378eeb", "Gateway": "172.19.0.1", "IPAddress": "172.19.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:13:00:02" } } } }]感觉 NetworkSettings 这里似乎有问题,但是不确定,也不知道如何解决(看网上的和之前的的 compose 文件配置项也大都是如此... 想不明白这次为啥就不行了)补充说明: 防火墙没开,IPtables 没装[root@localhost ~]# iptablesiptables v1.4.21: no command specifiedTry `iptables -h' or 'iptables --help' for more information.[root@localhost ~]# systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)[root@localhost ~]#上面已经提过了手动创建是可以远程访问的,而且我把手动创建的关掉,docker-compose中用6380 照样无法访问,所以端口和防护墙的原因应该是可以排除的
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版

    回答动态

    梨花未盛开:发布了悬赏问题9414754预计能赚取 11积分收益
    发布了悬赏问题9414754预计能赚取 11积分收益
    发布了悬赏问题9414754预计能赚取 0积分收益
    发布了悬赏问题9414754预计能赚取 11积分收益
    温柔腔:发布了悬赏问题9414754预计能赚取 0积分收益
    丑萌的人:发布了悬赏问题9414754预计能赚取 0积分收益
    花店没开:发布了悬赏问题9414754预计能赚取 0积分收益
    野性:发布了悬赏问题9414754预计能赚取 0积分收益
    念妻未解忧:发布了悬赏问题9414754预计能赚取 0积分收益
    夏目:发布了悬赏问题9414754预计能赚取 0积分收益