Docker阻止未经授权的访问



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。要解决此问题,您需要:

  1. 停止通过ports暴露端口(expose仅供参考(
  2. 不要附加youtube_cache执行external网络,而是将其保留在默认(内部(网络docker compose自动创建的网络上
  3. 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

最新更新