Profile picture

[Docker-Compose] 컨테이너에 고정 IP(Static IP) 할당

JaehyoJJAng2022년 04월 20일

static IP 할당

version: "3"
services:
  web:
    depends_on:
      - db    
    image: nginx:latest
    restart: always
    ports:
      - "8080:80"
    volumes:
      - ./myweb:/usr/share/nginx/html
    container_name: testweb
    networks:
      default_bridge:
        ipv4_address: 172.16.1.2

  db:
    image: mysql:5.7
    restart: always
    volumes:
      - db-data:/var/lib/mysql
    container_name: testdb
    env_file:
      - .env/.db.env
    networks:
      default_bridge:
        ipv4_address: 172.16.1.3

  nfs:
    build:
      context: NFS
      dockerfile: Dockerfile
    restart: always
    volumes:
      - storage:/vws
    networks:
      default_bridge:
        ipv4_address: 172.16.1.4
    
volumes:
  db-data:
  storage:

networks:
  default_bridge:
    ipam:
      driver: default
      config:
        - subnet: 172.16.1.0/24 # subnet 대역 지정

Loading script...