M1 Docker with lima

lima๋ž€

lima๋Š” ์ž๋™ํŒŒ์ผ๊ณต์œ ์™€ ํฌํŠธ ํฌ์›Œ๋”ฉ(WSL2๊ณผ ์œ ์‚ฌ)์„ ์ง€์›ํ•˜๋Š” linux vm๊ณผ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ œ๊ณตํ•œ๋‹ค.

lima๋Š” ์ผ์ข…์˜ ๋น„๊ณต์‹์ ์ธ "๋งฅ์„ ์œ„ํ•œ ์ปจํ…Œ์ด๋„ˆ"๋ผ ๋ณด๋ฉด ๋œ๋‹ค.

โœ… ์ž๋™ ํŒŒ์ผ ๊ณต์œ  โœ… ์ž๋™ ํฌํŠธ ํฌ์›Œ๋”ฉ โœ… ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋Šฅ ํƒ‘์žฌ

lima ๊ณต์‹ ๊นƒํ—ˆ๋ธŒ

lima ์„ค์น˜ ๋ฐฉ๋ฒ•

homebrew๋ฅผ ์ด์šฉํ•œ ์„ค์น˜

brew install lima

docker์™€ docker-compose๊ฐ€ ๊น”๋ ค์žˆ์ง€ ์•Š๋‹ค๋ฉด ๊ฐ™์ด ์„ค์น˜ํ•œ๋‹ค

brew install lima docker docker-compose

homebrew ์—†์ด ์„ค์น˜๋ฅผ ํ•˜๋ ค ํ•œ๋‹ค๋ฉด... ์ˆ˜๋™ ์„ค์น˜ ๋งค๋‰ด์–ผ

lima๊ฐ€ ์ œ๋Œ€๋กœ ์„ค์น˜ ๋๋Š”์ง€ ํ™•์ธ

limactl

\

lima์— docker ์„ค์น˜ ๋ฐฉ๋ฒ• ๋ฐ ๋ช…๋ น์–ด ์ข…๋ฅ˜

docker + lima config ํŒŒ์ผ

ํ•ด๋‹น ํ”„๋กœํ•„ ์ŠคํŽ™์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค

  • OS: Ubuntu 21.10 (Impish Indri)

  • CPU: 4 cores

  • Memory: 4 GiB

  • Disk: 100 GiB

  • Mounts: ~ (read-only), /tmp/lima (writable)

  • SSH: 127.0.0.1:60022

docker๊ฐ€ ์ถ”๊ฐ€๋œ docker.yaml ํ™˜๊ฒฝ์„ค์ • ํŒŒ์ผ

# Example to use Docker instead of containerd & nerdctl
# $ limactl start ./docker.yaml
# $ limactl shell docker docker run -it -v $HOME:$HOME --rm alpine

# To run `docker` on the host (assumes docker-cli is installed):
# $ export DOCKER_HOST=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock')
# $ docker ...

# This example requires Lima v0.8.0 or later
images:
# Hint: run `limactl prune` to invalidate the "current" cache
- location: "https://cloud-images.ubuntu.com/impish/current/impish-server-cloudimg-amd64.img"
  arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/impish/current/impish-server-cloudimg-arm64.img"
  arch: "aarch64"
mounts:
- location: "~"
- location: "/tmp/lima"
  writable: true
# containerd is managed by Docker, not by Lima, so the values are set to false here.
containerd:
  system: false
  user: false
provision:
- mode: system
  # This script defines the host.docker.internal hostname when hostResolver is disabled.
  # It is also needed for lima 0.8.2 and earlier, which does not support hostResolver.hosts.
  # Names defined in /etc/hosts inside the VM are not resolved inside containers when
  # using the hostResolver; use hostResolver.hosts instead (requires lima 0.8.3 or later).
  script: |
    #!/bin/sh
    sed -i 's/host.lima.internal.*/host.lima.internal host.docker.internal/' /etc/hosts
- mode: system
  script: |
    #!/bin/bash
    set -eux -o pipefail
    command -v docker >/dev/null 2>&1 && exit 0
    export DEBIAN_FRONTEND=noninteractive
    curl -fsSL https://get.docker.com | sh
    # NOTE: you may remove the lines below, if you prefer to use rootful docker, not rootless
    systemctl disable --now docker
    apt-get install -y uidmap dbus-user-session
- mode: user
  script: |
    #!/bin/bash
    set -eux -o pipefail
    systemctl --user start dbus
    dockerd-rootless-setuptool.sh install
    docker context use rootless
probes:
- script: |
    #!/bin/bash
    set -eux -o pipefail
    if ! timeout 30s bash -c "until command -v docker >/dev/null 2>&1; do sleep 3; done"; then
      echo >&2 "docker is not installed yet"
      exit 1
    fi
    if ! timeout 30s bash -c "until pgrep rootlesskit; do sleep 3; done"; then
      echo >&2 "rootlesskit (used by rootless docker) is not running"
      exit 1
    fi
  hint: See "/var/log/cloud-init-output.log". in the guest
hostResolver:
  # hostResolver.hosts requires lima 0.8.3 or later. Names defined here will also
  # resolve inside containers, and not just inside the VM itself.
  hosts:
    host.docker.internal: host.lima.internal
portForwards:
- guestSocket: "/run/user/{{.UID}}/docker.sock"
  hostSocket: "{{.Dir}}/sock/docker.sock"
message: |
  To run `docker` on the host (assumes docker-cli is installed), run the following commands:
  ------
  docker context create lima --docker "host=unix://{{.Dir}}/sock/docker.sock"
  docker context use lima
  docker run hello-world
  ------

๋‹ค๋ฅธ ์˜ˆ์‹œ ํŒŒ์ผ๋“ค์€ ์—ฌ๊ธฐ์„œ ํ™•์ธํ• ์ˆ˜ ์žˆ๋‹ค : lima/examples

docker.yaml์„ ์ด์šฉํ•œ ์„ค์น˜

docker๋ฅผ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•ด docker.yaml ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ lima๋ฅผ ์‹คํ–‰์‹œํ‚จ๋‹ค. ํ•ด๋‹น yaml ํŒŒ์ผ์ด ์žˆ๋Š” ๊ณณ์œผ๋กœ ์ด๋™ํ•œ ๋‹ค์Œ์— ํŒŒ์ผ์„ ์‹คํ–‰์‹œํ‚จ๋‹ค.

(์ฒจ๋ถ€ํŒŒ์ผ์˜ docker.yaml ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์œผ๋ฉด ๋œ๋‹ค.)

limactl start docker.yaml

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๊ธฐ๊นŒ์ง€ 5๋ถ„ ์ •๋„์˜ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ๋‹ค.\

์‹คํ–‰์ค‘์ธ ๋ฆฌ์ŠคํŠธ ํ™•์ธํ•˜๊ธฐ

limactl list

์„ค์น˜ํ•œ docker vm ์ด ์ž˜ ๋– ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

NAME      STATUS     SSH                ARCH       CPUS    MEMORY    DISK      DIR
docker    Running    127.0.0.1:51363    aarch64    4       4GiB      100GiB    /Users/taejun/.lima/docker

\

lima ์ ‘์† ๋ฐ docker ์‹คํ–‰ ๋ช…๋ น์–ด

๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ lima vm์œผ๋กœ ์ ‘์†ํ•œ๋‹ค

limactl shell docker

(์ดํ›„์— ๋‚˜์˜ค๋Š” ๋ช…๋ น์–ด๋“ค์€ ํ•ด๋‹น lima vm ์— ์ ‘์†ํ•˜์—ฌ ์ง„ํ–‰ํ•˜๋Š” ๋‹จ๊ณ„๋“ค์ด๋‹ค)

์ ‘์†ํ›„ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ docker ๊ฐ€ ์ž˜ ์‹คํ–‰๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

docker

๊ฐ„๋‹จํ•œ docker ๋ช…๋ น์–ด

command
description
Reference

docker-compose up [OPTIONS]

์„œ๋น„์Šค๋ฅผ ์œ„ํ•œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋นŒ๋“œ, (์žฌ)์ƒ์„ฑ, ์‹œ์ž‘ ๋ฐ ์—ฐ๊ฒฐ docker-compose.yml ํŒŒ์ผ์˜ ์œ„์น˜์—์„œ ์‹คํ–‰ ๊ฐ€๋Šฅ

docker ps [OPTIONS]

์ปจํ…Œ์ด๋„ˆ ์กฐํšŒ

docker images [OPTIONS] [REPOSITORY[:TAG]]

์ด๋ฏธ์ง€ ์กฐํšŒ

docker volume ls [OPTIONS]

๋ณผ๋ฅจ ์กฐํšŒ

docker-compose down

์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€, up์—์„œ ์ƒ์„ฑํ•œ ์ปจํ…Œ์ด๋„ˆ, ๋„คํŠธ์›Œํฌ, ๋ณผ๋ฅจ ๋ฐ ์ด๋ฏธ์ง€ ์ œ๊ฑฐ

docker rm [OPTIONS] CONTAINER [CONTAINER...]

ํ•˜๋‚˜ ์ด์ƒ์˜ ์ปจํ…Œ์ด๋„ˆ ์ œ๊ฑฐ

docker rmi [OPTIONS] IMAGE [IMAGE...]

ํ˜ธ์ŠคํŠธ ๋…ธ๋“œ์—์„œ ํ•˜๋‚˜ ์ด์ƒ์˜ ์ด๋ฏธ์ง€๋ฅผ ์ œ๊ฑฐ(๋ฐ ํƒœ๊ทธ ํ•ด์ œ)

docker volume prune [OPTIONS]

์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ชจ๋“  ๋กœ์ปฌ ๋ณผ๋ฅจ ์ œ๊ฑฐ

docker exec -it [์ปจํ…Œ์ด๋„ˆ๋ช… or ์ปจํ…Œ์ด๋„ˆID] bash

์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†

\

lima์—์„œ docker-compose ์‚ฌ์šฉํ•˜๊ธฐ

docker-compose.yml ๋ž€?

์—ฐ๊ฒฐ๋œ ๋‹ค์ˆ˜์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ•˜๋‚˜๋กœ ํ†ตํ•ฉํ•˜์—ฌ ๊ด€๋ฆฌํ•˜๋Š” ๋„๊ตฌ

docker-compose ์—์„œ๋Š” ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰์— ์‚ฌ์šฉ๋˜๋Š” ์˜ต์…˜๊ณผ ์ปจํ…Œ์ด๋„ˆ ๊ฐ„ ์˜์กด์„ฑ์„ ๋ชจ๋‘ docker-compose.yml ํŒŒ์ผ์— ์ ์–ด๋‘๊ณ , docker-compose ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ ๋ฐ ๊ด€๋ฆฌํ•œ๋‹ค.

docker-compose์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด : Docker Compose์™€ ๋ฒ„์ „๋ณ„ ํŠน์ง• \

lima์—์„œ docker-compose ์„ค์น˜ํ•˜๊ธฐ

docker-compose๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” lima vmํ™˜๊ฒฝ์— ์„ค์น˜ํ•˜์—ฌ์•ผ ํ•œ๋‹ค. ๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

sudo apt install docker-compose

์„ค์น˜ ํ›„ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ docker-compose๊ฐ€ ์ œ๋Œ€๋กœ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

docker-compose

docker-compose.yml ํ•ญ๋ชฉ

docker-composeํŒŒ์ผ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ•ญ๋ชฉ๋“ค๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ๋‹ค.

ํ•ญ๋ชฉ
example
description

version:

version: '3'

3๋งŒ ์“ฐ๊ฒŒ ๋˜๋ฉด ๊ฐ€์žฅ ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ์ธ์‹. ๊ตฌ์ฒด์ ์œผ๋กœ ๋ฒ„์ „์„ ๋ช…์‹œํ•  ์ˆ˜ ์žˆ๋‹ค.

services:

์„œ๋น„์Šค๋“ค์— ๋Œ€ํ•œ ์ •๋ณด ๋ช…์‹œ

container_name:

container_name: "local-mongodb"

์ปจํ…Œ์ด๋„ˆ๋ช… ๋ช…์‹œ

image:

image: mongo

๊ฐ€์ ธ์˜ฌ ์ด๋ฏธ์ง€ ๋ช…์‹œ

restart:

restart: always

์ปจํ…Œ์ด๋„ˆ ์ข…๋ฃŒ -> ์žฌ์‹คํ–‰

environment:

environment: MONGO_INITDB_DATABASE: local-db MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: password

์ปจํ…Œ์ด๋„ˆ์˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋ช…์‹œ

ports:

ports: - "27017:27017"

ํฌํŠธ ๋งคํ•‘ ์ •๋ณด ๋ช…์‹œ. (ํ˜ธ์ŠคํŠธ:์ปจํ…Œ์ด๋„ˆ)

volumes:

volumes: - "local-mongodb:/var/lib/mongo"

๋ณผ๋ฅจ ๋งคํ•‘ (ํ˜ธ์ŠคํŠธ:์ปจํ…Œ์ด๋„ˆ)

\

docker-comopse๋กœ mongodb, mysql, redis ํ™˜๊ฒฝ ์„ธํŒ…ํ•˜๊ธฐ

๋ณธ ์˜ˆ์‹œ์—์„œ๋Š” mongodb, mysql, redis ๋ฅผ ํฌํ•จํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ docker-comopse๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ค์น˜ํ•œ๋‹ค.

docker-compose up์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ๋„์šฐ๊ธฐ

docker-compose ํŒŒ์ผ์ด ์žˆ๋Š” ์œ„์น˜๋กœ ์ด๋™ํ•˜์—ฌ ํ•ด๋‹น ํŒŒ์ผ์„ ์‹คํ–‰์‹œํ‚จ๋‹ค. (์ฒจ๋ถ€ํŒŒ์ผ์˜ docker-compose.yml ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์œผ๋ฉด ๋œ๋‹ค.)

docker-compose up -d

(-d ์˜ต์…˜: ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ๋Œ์•„๊ฐˆ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.)

ํ•ด๋‹น ๋ช…๋ น์–ด๋Š” ํŒŒ์ผ์ด๋ฆ„์ด docker-compose.yml์ธ ๊ฒฝ์šฐ์— ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๊ณ , ํŒŒ์ผ ์ด๋ฆ„์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ๋ผ๋ฉด ๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

docker-compose -f docker-compose-test.yml up
docker-compose -f {ํŒŒ์ผ์ด๋ฆ„} up

(-f ์˜ต์…˜: ๊ธฐ๋ณธ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” docker-compose.yml์ด ์•„๋‹Œ ๋ณ„๋„์˜ ํŒŒ์ผ๋ช…์„ ์‹คํ–‰ํ•  ๋•Œ ์‚ฌ์šฉ)

docker image ํ™•์ธํ•˜๊ธฐ

๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ docker image๋ฅผ ํ™•์ธํ• ์ˆ˜ ์žˆ๋‹ค.

docker images -a

(-a ์˜ต์…˜: ์‹คํ–‰์ค‘์ด์ง€ ์•Š๋”๋ผ๋„ ์ „์ฒด ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณด์—ฌ์คŒ)

๋ฐฉ๊ธˆ์ „ docker-compose up์„ ํ•˜๋ฉด์„œ ๋‹ค์šด๋ฐ›์€ mongo, redis, mysql ์ด๋ฏธ์ง€๊ฐ€ ์žˆ๋Š”๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.\

docker process ํ™•์ธํ•˜๊ธฐ

๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ docker์— ๋– ์žˆ๋Š” process๋ฅผ ํ™•์ธํ• ์ˆ˜ ์žˆ๋‹ค.

docker ps -a

(-a ์˜ต์…˜: ์‹คํ–‰์ค‘์ด์ง€ ์•Š๋”๋ผ๋„ ์ „์ฒด ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณด์—ฌ์คŒ)

๋ฐฉ๊ธˆ์ „ docker-compose up์œผ๋กœ ์‹คํ–‰์‹œํ‚จ mongo, redis, mysql ์ด๋ฏธ์ง€๊ฐ€ ์žˆ๋Š”๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.\

docker-compose down์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ฆฌ๊ธฐ

๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ํ•ด๋‹น ํŒŒ์ผ๋กœ ๋„์šด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋‚ด๋ฆด ์ˆ˜ ์žˆ๋‹ค.

docker-compose down

mongodb์˜ docker-compose.yml

version: '3'

services:
  local-mongodb:
    container_name: "local-mongodb"
    image: mongo
    restart: always 
    environment:
      MONGO_INITDB_DATABASE: local-db
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: password
    ports:
      - "27017:27017"
    volumes:
      - "local-mongodb:/var/lib/mongo"

volumes:
  local-mongodb:

๊ฐ„๋‹จํ•œ MongoDB ๋ช…๋ น์–ด

command
example
description

mongo admin -u [์œ ์ €๋ช…] -p [๋น„๋ฐ€๋ฒˆํ˜ธ]

mongo admin -u root -p password

mongodb ์ ‘์†

use [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…]

use mydb

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ & ์‚ฌ์šฉ

show dbs

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์กฐํšŒ

db

ํ˜„์žฌ ์‚ฌ์šฉ์ค‘์ธ DB ์กฐํšŒ

db.createCollection("[์ปฌ๋ ‰์…˜๋ช…]")

db.createCollection("person")

collection ์ƒ์„ฑ

show collections

collection ์กฐํšŒ

db.[์ปฌ๋ ‰์…˜๋ช…].insert([JSON format])

db.person.insert({"name" : "hyoung", "email" : "[joonhyuck-hyoung@nhn-commerce.com](mailto:joonhyuck-hyoung@nhn-commerce.com)"})

document(๋ฐ์ดํ„ฐ) ์ƒ์„ฑ

db.[์ปฌ๋ ‰์…˜๋ช…].find()

db.person.find()

document ์กฐํšŒ

db.[์ปฌ๋ ‰์…˜๋ช…].remove([JSON format])

db.person.remove({"name":"hyoung"})

document ์‚ญ์ œ

db.[์ปฌ๋ ‰์…˜๋ช…].drop()

db.person.drop()

collection ์‚ญ์ œ

\

mysql์˜ docker-compose.yml

local-mysql:
    image: mysql/mysql-server:8.0.23
    container_name: local-mysql
    hostname: local-mysql
    restart: always
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: accounts
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: authorization
    volumes:
      - "local-mysql:/var/lib/mysql"

\

lima์—์„œ docker๋กœ ๋„์šด mysql ์ ‘์†ํ•˜๊ธฐ


docker mysql container ์ ‘์†: $ docker exec -it local-mysql bash

mysql ์ ‘์†: $ mysql -h localhost -P 13306 -u root -p authorization

redis์˜ docker-compose.yml

local-redis:
    container_name: local-redis
    hostname: local-redis
    image: redis
    restart: always
    ports:
      - "6379:6379"
    volumes:
      - "local-redis:/var/lib/"

lima์—์„œ docker๋กœ ๋„์šด redis ์ ‘์†ํ•˜๊ธฐ


docker redis container ์ ‘์†: $ docker exec -it local-redis redis-cli\

\

docker volume - mount

  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ์—์„œ ์ž‘์„ฑ๋˜๊ฑฐ๋‚˜ ์ˆ˜์ •๋œ ํŒŒ์ผ์€ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ํŒŒ๊ธฐ๋˜๋ฉด ํ˜ธ์ŠคํŠธ๋„ ํ•จ๊ป˜ ์‚ญ์ œ๋œ๋‹ค.

  • ํ˜ธ์ŠคํŠธ์ชฝ ํŒŒ์ผ ์‹œ์Šคํ…œ์— ๋ฐ์ดํ„ฐ๋ฅผ ๋งˆ์šดํŠธํ•˜๋ฉด ์ปจํ…Œ์ด๋„ˆ์—์„œ ์‚ญ์ œํ•ด๋„ ํ˜ธ์ŠคํŠธ ํŒŒ์ผ ์‹œ์Šคํ…œ์— ๋‚จ์•„์žˆ๊ฒŒ ๋œ๋‹ค.

  • volume ์ข…๋ฅ˜

  1. Bind Mount ํ˜ธ์ŠคํŠธ ํ™˜๊ฒฝ์˜ ํŠน์ • ๊ฒฝ๋กœ๋ฅผ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€ ๋ณผ๋ฅจ ๊ฒฝ๋กœ์™€ ์—ฐ๊ฒฐํ•˜์—ฌ ๋งˆ์šดํŠธํ•œ๋‹ค. ์ด ๋ฐฉ๋ฒ•์€ ๋ณด์•ˆ์— ์˜ํ–ฅ์„ ๋ฏธ์น  ์ˆ˜ ์žˆ์Œ

  2. Volume (๊ฐ€์žฅ ์ผ๋ฐ˜์ ) ๋„์ปค ๋ณผ๋ฅจ์€ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ์—์„œ ๋„์ปค ๋‚ด๋ถ€์— ๋„์ปค ์—”์ง„์ด ๊ด€๋ฆฌํ•˜๋Š” ๋ณผ๋ฅจ์„ ์ƒ์„ฑ ์ƒ์„ฑ๋œ ๋ณผ๋ฅจ์€ ํ˜ธ์ŠคํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ /var/lib/docker/volumes ๊ฒฝ๋กœ์— ์ €์žฅ๋˜๋ฉฐ, ๋„์ปค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ด€๋ฆฌ๊ฐ€ ์šฉ์ด

  3. tmpfs Mount ํ˜ธ์ŠคํŠธ์˜ ํŒŒ์ผ ์‹œ์Šคํ…œ์ด ์•„๋‹Œ, ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉ

\

Volume mount ํ…Œ์ŠคํŠธ

  • ์‚ฌ์ „์ค€๋น„ mysql image ๊ฐ€ ์กด์žฌํ•˜๋Š” docker-compose.yml ํŒŒ์ผ

version: '3'

services:
  local-mysql:
    image: mysql/mysql-server:8.0.23
    container_name: local-mysql
    hostname: local-mysql
    restart: always
    ports:
      - "13306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: mydb
    volumes:
      - "local-mysql:/var/lib/mysql"

volumes:
  local-mysql:

\

1.MySQL

  1. mysql image ๊ฐ€ ์กด์žฌํ•˜๋Š” docker-compose.yml ์„ ํ†ตํ•ด ์ปจํ…Œ์ด๋„ˆ ๋นŒ๋“œ docker-compose up -d --f

  2. ์‹คํ–‰์ค‘์ธ mysql ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์† docker exec -it [์ปจํ…Œ์ด๋„ˆ๋ช… or ์ปจํ…Œ์ด๋„ˆID] bash

  3. mysql ์ ‘๊ทผ mysql -u [์œ ์ €๋ช…] -p [๋น„๋ฐ€๋ฒˆํ˜ธ]

  4. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์‚ฌ์šฉ use [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ช…];

  5. ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ํ…Œ์ด๋ธ” (member_table) ์ƒ์„ฑ

CREATE TABLE member_table (
 seq        INT NOT NULL AUTO_INCREMENT,
 mb_id     VARCHAR(20),
 mb_pw    VARCHAR(20),
 address   VARCHAR(50),
 mb_tell    VARCHAR(50),
  PRIMARY KEY(seq)
)

6. ๋”๋ฏธ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€ INSERT INTO member_table(mb_id, mb_pw, address, mb_tell) VALUES("test", "test", "test", "test"); 7. ๋ฐ์ดํ„ฐ ํ™•์ธ SELECT * FROM member_table;

+-----+-------+-------+---------+---------+
| seq | mb_id | mb_pw | address | mb_tell |
+-----+-------+-------+---------+---------+
|   1 | test  | test  | test    | test    |
|   2 | test  | test  | test    | test    |
|   3 | test  | test  | test    | test    |
|   4 | test  | test  | test    | test    |
|   5 | test  | test  | test    | test    |
|   6 | test  | test  | test    | test    |
|   7 | test  | test  | test    | test    |
|   8 | test  | test  | test    | test    |
|   9 | test  | test  | test    | test    |
|  10 | test  | test  | test    | test    |
|  11 | test  | test  | test    | test    |
|  12 | test  | test  | test    | test    |
+-----+-------+-------+---------+---------+
12 rows in set (0.00 sec)

8. mysql ์ ‘๊ทผ ์ข…๋ฃŒ exit

2. volume mount ํ™•์ธ

  1. docker volume ์ƒ์„ฑ ํ™•์ธ docker volume ls

DRIVER    VOLUME NAME
local     docker_local-mysql

2. lima ํ™˜๊ฒฝ ๋‚ด์˜ ๋ฌผ๋ฆฌ์  ์ €์žฅ์žฅ์†Œ ํ™•์ธ cd ~/.local/share/docker/volumes/ cd _data ์ ‘๊ทผ์ด ๊ฑฐ๋ถ€๋˜๋ฉด sudo -s 3. ํ…Œ์ŠคํŠธ์šฉ์œผ๋กœ ์ƒ์„ฑํ•œ ํ…Œ์ด๋ธ” (member_table) ํ™•์ธ

root@lima-default:/home/taejun.linux/.local/share/docker/volumes/docker_local-mysql/_data/mydb# ls member_table.ibd

\

mount ๊ณผ์ • ํ™•์ธ ๋ฐฉ๋ฒ•

  1. docker-compose down => docker-compose up ์ดํ›„์—๋„ lima ์œ„์— ๋ฐ์ดํ„ฐ๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ์—ฌ๋ถ€ ํ™•์ธ

  2. docker rm -f [์ปจํ…Œ์ด๋„ˆ๋ช…] ์„ ํ†ตํ•ด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ง€์›Œ๋„ lima ์œ„์— ๋ฐ์ดํ„ฐ๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ์—ฌ๋ถ€ ํ™•์ธ

๋ถ€๋ก

์˜๋ฌธ์ 

mongodb์˜ ๋ฐ์ดํ„ฐ๋Š” mysql์™€ ๋‹ค๋ฅด๊ฒŒ ์ง€์ •๋œ volume์ด ์•„๋‹Œ ํ•ด์‹œ๊ฐ’์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ํด๋”์— ์ €์žฅ๋œ๋‹ค.

taejun@lima-default:~/.local/share/docker/volumes$ cd cea1548f8644bcb41ac708a0b3d204f2616f20a35159f25b42aed9645b6d6197/_data/
taejun@lima-default:~/.local/share/docker/volumes/cea1548f8644bcb41ac708a0b3d204f2616f20a35159f25b42aed9645b6d6197/_data$ ls
WiredTiger         collection-0-4752117110476890269.wt  index-3-4752117110476890269.wt  mongod.lock
WiredTiger.lock    collection-2-4752117110476890269.wt  index-5-4752117110476890269.wt  sizeStorer.wt
WiredTiger.turtle  collection-4-4752117110476890269.wt  index-6-4752117110476890269.wt  storage.bson
WiredTiger.wt      collection-7-4752117110476890269.wt  index-8-4752117110476890269.wt
WiredTigerHS.wt    diagnostic.data                      index-9-4752117110476890269.wt
_mdb_catalog.wt    index-1-4752117110476890269.wt       journal

\

๊ธฐ์กด ํ”„๋กœ์ ํŠธ์˜ docker-compose ํŒŒ์ผ์„ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๊ฒช์„ ์ˆ˜ ์žˆ๋Š” ์–ด๋ ค์›€

๊ธฐ์กด์˜ docker image๋“ค์€ arm64/v8 ๊ธฐ๋ฐ˜์œผ๋กœ ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋˜์–ด์žˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ์— ๊ธฐ์กด ์ด๋ฏธ์ง€๋ฅผ ์ด์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋  ๊ฒฝ์šฐ m1 ํ”Œ๋žซํผ ํ™˜๊ฒฝ์ธ linux/x86_64 ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— docker-comopse up์„ ํ•  ๊ฒฝ์šฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ํ•ด๋‹น ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ• ์ˆ˜ ์žˆ์—ˆ๋‹ค.

  1. docker-compose file ์— ๋‹ค์Œ์˜ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

platform: linux/x86_64

์ด ๋ฐฉ๋ฒ•์€ ํ•ด๋‹น ์ด๋ฏธ์ง€๊ฐ€ ์ด๋ฏธ buildx์˜ต์…˜์œผ๋กœ ๋นŒ๋“œ๋˜์–ด ๋„์ปค ํ—ˆ๋ธŒ์— ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋งŒ ํ†ตํ•œ๋‹ค.

2. ํ•ด๋‹น ์ด๋ฏธ์ง€๋ฅผ docker buildx๋ฅผ ์ด์šฉํ•˜์—ฌ m1 ํ”Œ๋žซํผ๋„ ์ง€์›ํ• ์ˆ˜ ์žˆ๋„๋ก ์žฌ๋นŒ๋“œ ํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• linux/x86_64 ๋„ ์ง€์›ํ•˜๋Š” ๋ฉ€ํ‹ฐํ”Œ๋žซํผ ๋นŒ๋“œ์™€ ๊ด€๋ จ๋œ ๋‚ด์šฉ์€ ๋‹ค์Œ์˜ ๋งํฌ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

Docker buildx build(at M1 Macbook)

์ด์ œ ํ•ด๊ฒฐ์ด ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๊ตฌ๊ธ€๋ง์œผ๋กœ...

์ถ”๊ฐ€ ์ง„ํ–‰ํ•  ๋‚ด์šฉ

ํ˜„์žฌ redis, mongo, mysql์€ m1ํ™˜๊ฒฝ์—์„œ lima๋ฅผ ์ด์šฉํ•˜์—ฌ docker-compose ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„์› ์ง€๋งŒ, kafka + zookeepr์˜ ๊ฒฝ์šฐ์—๋Š” docker-compose ํŒŒ์ผ์„ ์ด์šฉํ•œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„์šฐ๋Š” ๊ฒƒ์— ์–ด๋ ค์›€์„ ๊ฒช๊ณ ์žˆ๋‹ค.

ํ•ด๋‹น ๋ถ€๋ถ„์€ ์ถ”๊ฐ€์ ์œผ๋กœ ์„ฑ๊ณตํ•˜๋Š” ๋ฐ๋กœ ๋ณธ ๋‚ด์šฉ์— ์ถ”๊ฐ€ํ•  ์˜ˆ์ •์ด๋‹ค.

docker-compose๋ฅผ ์ด์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„์šฐ๊ฒŒ ๋˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋‚˜๋ฉด์„œ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋– ์žˆ์ง€ ๋ชปํ•˜๊ณ  ์ž๊พธ ์ฃฝ๋Š” ํ˜„์ƒ์„ ๊ฒช๊ณ  ์žˆ๋‹ค.

standard_init_linux.go:228: exec user process caused: exec format error

์ถœ์ฒ˜ : Cho Yoohwa, Kang Sunghyuk, Hyoung Joonhyuck

Last updated