docker compose为容器设置自定义IP地址

测试环境有时需要为容器设置固定IP,以启动redis为示例docker-compose.yml如下所示:

version: "3.7"

services:
  redis:
    container_name: redis
    hostname: redis
    image: redis:5.0.7
    networks:
      redis:
        ipv4_address: 172.18.0.5

    ports:
      - 6379:6379/tcp
    restart: always
    volumes:
      - /data/reids/data:/data:rw
      #- /data/config/redis.conf:/usr/local/etc/redis/redis.conf
      #- ./config/redis.conf:/usr/local/etc/redis/redis.conf
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime:ro
    logging:
      driver: json-file
      options:
        max-file: '3'
        max-size: 100m

networks:
  redis:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: "172.18.0.0/24"

 

你可能感兴趣的:(docker,docker,容器,redis,服务器)