1. docker compose 실행할 수 있는 환경 세팅

    sudo apt-get update
    sudo apt-get install docker-compose
    
  2. docker-compose.yml 파일 생성

    version: '3'
    services:
      db:
        image: mysql:8.0
        container_name: mysql-meetup # 이 컨테이너 이름은 내가 하고싶은대로 해도된다.
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: root
          TZ: Asia/Seoul
        ports:
          - 3306:3306
        volumes:
          - ./mysql-init-files/:/docker-entrypoint-initdb.d
    			# mysql폴더를 마운트해줘야 database 정보들이 docker-compose down/up 할때마다 초기화되지 않는다.
          - ./data:/var/lib/mysql
        platform: linux/x86_64
    
      # httpd: apache 추가
      httpd:
        image: httpd:2.4
        ports:
          - 80:80
        volumes:
          - ./html:/usr/local/apache2/htdocs
          - ./conf:/etc/httpd/conf.d
    
  3. docker-compose 실행 명령어

    sudo docker-compose up -d
    
    sudo docker-compose down
    
    sudo docker-compose stop
    

참고사항



MSA - 하나의 인스턴스에 Docker-compose 이용해서 4개의 mysql 생성

version: '3'
services:
  db_instance_user:
    image: mysql:8.0
    container_name: mysql-user-container
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      TZ: Asia/Seoul
    ports:
      - "3306:3306" # 외부 포트 3306을 컨테이너 내부의 3306 포트와 연결
    volumes:
      - ./mysql-init-files/:/docker-entrypoint-initdb.d
      - ./db_instance_user:/var/lib/mysql # 데이터베이스 파일을 컨테이너 내부의 다른 경로로 마운트

  db_instance_recipe:
    image: mysql:8.0
    container_name: mysql-recipe-container
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      TZ: Asia/Seoul
    ports:
      - "3307:3306"
    volumes:
      - ./mysql-init-files/:/docker-entrypoint-initdb.d
      - ./db_instance_recipe:/var/lib/mysql

  db_instance_wriggle:
    image: mysql:8.0
    container_name: mysql-wriggle-container
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      TZ: Asia/Seoul
    ports:
      - "3308:3306"
    volumes:
      - ./mysql-init-files/:/docker-entrypoint-initdb.d
      - ./db_instance_wriggle:/var/lib/mysql

  db_instance_chat:
    image: mysql:8.0
    container_name: mysql-chat-container
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      TZ: Asia/Seoul
    ports:
      - "3309:3306"
    volumes:
      - ./mysql-init-files/:/docker-entrypoint-initdb.d
      - ./db_instance_chat:/var/lib/mysql