【问题标题】:Docker redis unauthorised accessDocker redis 未授权访问
【发布时间】:2021-09-19 02:41:36
【问题描述】:

Digital Ocean 告诉我,Redis 可能无意中暴露数据或配置错误以允许未经授权的访问。

一个 telnet 命令确认了这一点。

但是,我需要允许我在同一网络上的 docker 容器访问 Redis;启用外部访问似乎是唯一的方法!

如何配置我的 docker-compose 以允许两个容器之间的安全访问:

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 security docker-compose redis


    【解决方案1】:

    问题是您的 docker-compose 文件配置为将 youtube_cache 容器的端口 6379 暴露给 youtube 网络,恰好是 external。 要解决这个问题,您需要:

    1. 停止通过ports 暴露端口(@98​​7654324@ 仅供参考);
    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
    

    【讨论】:

    • 太棒了,谢谢!我认为“默认”不是内部网络所需的实际名称,还是 docker-compose 将其作为关键字来指定?
    • 我的荣幸。 default 是实际的网络名称 - 请参阅 docs.docker.com/compose/networking/…
    • @MikeThrussell 如果它解决了您的问题,请考虑接受此答案。 ;)
    猜你喜欢
    • 2015-03-05
    • 2022-10-20
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多