도컀 Docker

DockerλŠ” μ»¨ν…Œμ΄λ„ˆλ₯Ό μ‚¬μš©ν•΄ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ μ‹ μ†ν•˜κ²Œ ꡬ좕, ν…ŒμŠ€νŠΈ 및 배포할 수 μžˆλŠ” μ†Œν”„νŠΈμ›¨μ–΄ ν”Œλž«νΌμž…λ‹ˆλ‹€.

μ €λŠ” 개발 ν™˜κ²½μ„ μ€€λΉ„ν•˜κΈ° μœ„ν•΄ 도컀 Dockerλ₯Ό ν™œμš©ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

도컀 μ„€μΉ˜

μ„€μΉ˜ νŒŒμΌμ„ λ‚΄λ €λ°›μ•„ μ„€μΉ˜ν•©λ‹ˆλ‹€. λ§ν¬λŠ” μœˆλ„μš°μ¦ˆμ—μ„œ 도컀λ₯Ό μ‚¬μš©ν•˜κΈ° μœ„ν•΄ ν•„μš”ν•©λ‹ˆλ‹€.

이미지 검색

MariaDB 이미지λ₯Ό κ²€μƒ‰ν•©λ‹ˆλ‹€.

PS> docker search mariadb
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mariadb                                                   MariaDB is a community-developed fork of MyS…   2596                [OK]
bitnami/mariadb                                           Bitnami MariaDB Docker Image                    86                                      [OK]
linuxserver/mariadb                                       A Mariadb container, brought to you by Linux…   59
toughiq/mariadb-cluster                                   Dockerized Automated MariaDB Galera Cluster …   37                                      [OK]

이미지 λ‹€μš΄λ‘œλ“œ

곡식 이미지λ₯Ό λ‹€μš΄λ‘œλ“œν•©λ‹ˆλ‹€.

PS> docker pull mariadb

μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰

λ‹€μš΄λ‘œλ“œ 받은 μ΄λ―Έμ§€λ‘œ μ»¨ν…Œμ΄λ„ˆλ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€.

μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰ μΈμˆ˜μ™€ ν™˜κ²½λ³€μˆ˜λŠ” docker hub mariadbμ—μ„œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

docker-compose

docker-composeλ₯Ό μ‚¬μš©ν•˜λ©΄ μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰μ‹œ λ³΅μž‘ν•˜κ²Œ μž…λ ₯ν•΄μ•Ό ν•˜λŠ” 인수λ₯Ό 미리 μ€€λΉ„ν•˜κ³  μ»¨ν…Œμ΄λ„ˆ μ‹€ν–‰, 쀑지, 제거 절차λ₯Ό μ†μ‰½κ²Œ μ²˜λ¦¬ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ λ‹Ήν•œ 디렉터리에 docker-compose.yml νŒŒμΌμ„ μ•„λž˜μ˜ λ‚΄μš©μœΌλ‘œ μž‘μ„±ν•©λ‹ˆλ‹€.

μ‚¬μš©μž ν”„λ‘œν•„ 디렉터리에 docker 디렉터리λ₯Ό λ§Œλ“€κ³  μ»¨ν…Œμ΄λ„ˆ 이름에 ν•΄λ‹Ήν•˜λŠ” mariadb 디렉터리λ₯Ό λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€. κ·Έ μ•ˆμ— config, data 디렉터리λ₯Ό μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€. docker-compose.yml νŒŒμΌμ€ mariadb 디렉터리에 μžˆμŠ΅λ‹ˆλ‹€.

μ‚¬μš©μž ν”„λ‘œν•„ λ””λ ‰ν„°λ¦¬λŠ” μœˆλ„μš°μ¦ˆ 탐색기λ₯Ό μ—΄κ³  μ£Όμ†Œμ°½μ— %userprofile% 을 μž…λ ₯ν•˜λ©΄ λ°”λ‘œ 이동할 수 μžˆμŠ΅λ‹ˆλ‹€.

PS> tree .
C:\USERS\{username}\DOCKER
└─mariadb
β”œβ”€config
└─data

docker-compose.yml 파일의 λ‚΄μš©μž…λ‹ˆλ‹€.

version: "3.1"

services:
  db:
    container_name: mariadb
    image: mariadb:latest
    restart: always
    ports:
      - 3306:3306
    volumes:
      - /c/Users/{username}/docker/mariadb/data:/var/lib/mysql
      - /c/Users/{username}/docker/mariadb/config:/etc/mysql/conf.d
    environment:
      MYSQL_ROOT_PASSWORD: { password }
      TZ: Asia/Seoul

{username}: μœˆλ„μš°μ¦ˆ μ‚¬μš©μž κ³„μ •μ΄λ¦„μœΌλ‘œ 변경이 ν•„μš”ν•©λ‹ˆλ‹€. {password}: mariadb root κ³„μ •μ˜ λΉ„λ°€λ²ˆν˜Έλ‘œ 변경이 ν•„μš”ν•©λ‹ˆλ‹€. (μ›ν•˜λŠ” κ°’μœΌλ‘œ λ³€κ²½ν•©λ‹ˆλ‹€.)

mariadb/config λ””λ ‰ν„°λ¦¬μ—λŠ” 미리 κ΅¬μ„±ν•œ cnf νŒŒμΌμ„ μΆ”κ°€ν•©λ‹ˆλ‹€.

μ œκ°€ μ‚¬μš©ν•˜λŠ” λ¬Έμžμ…‹κ³Ό 정렬을 κ΅¬μ„±ν•œ mariadb.cnf 파일의 λ‚΄μš©μ€ μ•„λž˜μ™€ κ°™μŠ΅λ‹ˆλ‹€.

# MariaDB-specific config file.
# Read by /etc/mysql/my.cnf

[client]
# Default is Latin1, if you need UTF-8 set this (also in server section)
#default-character-set = utf8
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
#
# * Character sets
#
# Default is Latin1, if you need UTF-8 set all this (also in client section)
#
#character-set-server  = utf8
#collation-server      = utf8_general_ci
#character_set_server   = utf8
#collation_server       = utf8_general_ci
# Import all .cnf files from configuration directory
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

!includedir /etc/mysql/mariadb.conf.d/

docker-compose.yml νŒŒμΌμ„ μž‘μ„±ν–ˆμœΌλ©΄, ν•΄λ‹Ή 파일이 μžˆλŠ” μœ„μΉ˜μ—μ„œ μ•„λž˜ λͺ…λ ΉμœΌλ‘œ μ»¨ν…Œμ΄λ„ˆλŠ” μž‘μ„±ν•˜κ³  μ‹€ν–‰ν•©λ‹ˆλ‹€.

PS> docker-compose up -d

μ»¨ν…Œμ΄λ„ˆ μƒνƒœλ₯Ό ν™•μΈν•˜λ €λ©΄ ps λͺ…령을 μ‚¬μš©ν•©λ‹ˆλ‹€.

PS> docker-compose ps
The system cannot find the path specified.
 Name               Command             State           Ports
----------------------------------------------------------------------
mariadb   docker-entrypoint.sh mysqld   Up      0.0.0.0:3306->3306/tcp

μ»¨ν…Œμ΄λ„ˆλ₯Ό μ€‘μ§€ν•˜λ €λ©΄ stop λͺ…령을 μ‚¬μš©ν•©λ‹ˆλ‹€.

PS> docker-compose stop

μ»¨ν…Œμ΄λ„ˆλ₯Ό μ‹œμž‘ν•˜λ €λ©΄ start λͺ…령을 μ‚¬μš©ν•©λ‹ˆλ‹€.

PS> docker-compose start

μ»¨ν…Œμ΄λ„ˆλ₯Ό μ œκ±°ν•˜λ €λ©΄ down λͺ…령을 μ‚¬μš©ν•©λ‹ˆλ‹€.

ps> docker-compose down