docker - Docker redis 未授权访问
问题描述
Digital Ocean 告诉我,Redis 可能会无意中暴露数据或配置错误以允许未经授权的访问。
一个 telnet 命令证实了这一点。
但是,我需要允许我在同一网络上的 docker 容器访问 Redis;启用外部访问似乎是唯一的方法!
如何配置我的 docker-compose 以允许在 2 个容器之间安全地访问:
version: '2'
services:
redis:
networks:
- youtube
image: redis
ports:
- 6379:6379
expose:
- "6379"
container_name: youtube_cache
command: sh -c 'redis-server --bind 0.0.0.0'
restart: always
node:
tty: true # Enables debugging capabilities when attached to this container.
image: 'docker.io/bitnami/node:12-debian-10'
command: sh -c 'npm install && npm rebuild && node app'
volumes:
- .:/app
links:
- redis
environment:
- REDIS_URL=redis://youtube_cache
container_name: youtube_scraper
networks:
- youtube
restart: always
networks:
youtube:
external: true
解决方案
问题是您的 docker-compose 文件配置为将youtube_cache容器的端口 6379 暴露给youtube网络,而external
. 要解决此问题,您需要:
- 停止通过暴露端口
ports
(expose
仅供参考); - 不要附加youtube_cache做
external
网络,而只是将它留在默认(内部)网络 docker-compose 自动创建; - 将youtube_scraper容器也添加到该默认网络,以便它可以与第一个网络通信。
version: '3'
services:
redis:
image: redis
container_name: youtube_cache
command: sh -c 'redis-server --bind 0.0.0.0'
restart: always
node:
tty: true # Enables debugging capabilities when attached to this container.
image: 'docker.io/bitnami/node:12-debian-10'
command: sh -c 'npm install && npm rebuild && node app'
volumes:
- .:/app
links:
- redis
environment:
- REDIS_URL=redis://youtube_cache
container_name: youtube_scraper
networks:
- youtube
- default
restart: always
networks:
youtube:
external: true
推荐阅读
- c - 无法将字符串从 C 传输到 Ada
- javascript - 无法获取(路径)Reactjs,nodejs
- katex - 为什么我的 \right)、\right] 和 \right} 的样式是红色的?
- r - 如何根据相同的类别列和时间列接收列的特定行的总和
- java - Kotlin 中的 Java 类型
- amazon-web-services - “BearSSL::WiFiClientSecure 类”没有名为“loadCertificate”的成员
- spring-data-jpa - 无法在 Hibernate/JPA/Spring boot 项目中创建具有 3 个字段的复合 PK
- c++ - 在运行时更改 qml 样式
- php - sqlsrv_prepare():必须是资源类型,bool 给定 php_sqlsrv 80
- python - Python 如何使用 github api 从 GitHub 下载存储库 zip 文件