M1에 Docker 설치하는 방법

|

M1에 Docker 설치하는 방법

Docker 다운로드

Docker가 M1에서 동작할 수 있도록 정식 버전이 릴리즈되어 있습니다.

image

여기에서 다운로드할 수 있습니다.

Docker Subscription Service Agreement

image

Accept를 누르고 계속 진행합니다.

Tutorial

설치를 하고나면 간단한 튜토리얼을 해볼 수 있습니다.

image

clone, build, run, share에 대한 간단한 명령어를 확인할 수 있습니다.

터미널에서 확인

터미널에서도 Docker 명령어가 잘 동작하는 것을 확인합니다.

image

실제 동작 확인

여기서는 RabbitMQ를 이용해서 테스트 해보도록 하겠습니다. 아래 명령어를 입력하면 RabbitMQ 이미지까지 자동으로 다운로드 후 실행까지 합니다.

$ docker run -d --hostname rabbit --name rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management

Unable to find image 'rabbitmq:3-management' locally
3-management: Pulling from library/rabbitmq
a39c84e173f0: Pull complete
7d3994c28245: Pull complete
10c911d5c079: Pull complete
769f1e4dc40b: Pull complete
2090f091d001: Pull complete
f9e692861b3e: Pull complete
d26c4b0e32ac: Pull complete
3cf30fecd6f0: Pull complete
c5b6ca5b444e: Pull complete
aa1dff4734e4: Pull complete
Digest: sha256:4c4b66ad5ec40b2c27943b9804d307bf31c17c8537cd0cd107236200a9cd2814
Status: Downloaded newer image for rabbitmq:3-management
501592f6fdc53e1da8ff527b2b4cf7853ce28bf05dd06e3c62fbac6e747e4945

잘 동작하는지 확인해봅니다.

$ docker ps -a

CONTAINER ID   IMAGE                   COMMAND                  CREATED          STATUS          PORTS                                                                                                         NAMES
501592f6fdc5   rabbitmq:3-management   "docker-entrypoint.s…"   28 seconds ago   Up 27 seconds   4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp   rabbit

그리고 사파리나 크롬 등에서 http://localhost:15672/에 접속해서 다음 화면이 잘 나오는지 확인합니다.

image

Redis Pub/Sub 예제

|

Redis Pub/Sub 예제

Redis 설치

Redis는 Docker를 이용해서 설치해줍니다.

docker run --name redis -d -p 6379:6379 redis


subscriber.py

import redis

r = redis.Redis(host="localhost", port=6379, db=0)
s = r.pubsub()

s.subscribe("snowdeer_channel")

while True:
    print("waiting message...")
    res = s.get_message(timeout=5)
    if res is not None:
        print(f"res: {res}")


publisher.py

import redis
import datetime

r = redis.Redis(host="localhost", port=6379, db=0)

msg = f"[{datetime.datetime.now()}] hello, snowdeer +___+"
r.publish(channel="snowdeer_channel",
          message=msg)

print(f"Message is sent !!\n{msg}")

여러 개의 Topic을 Subscription 하는 예제

import redis


def main():
    r = redis.Redis(host="localhost", port=6379, db=0)
    s = r.pubsub()

    s.subscribe('chat')
    s.subscribe('event')

    while True:
        print('waiting message...')
        res = s.get_message(timeout=5)
        if res is not None:
            if res['type'] == 'message':
                handle_message(res['channel'], res['data'])


def handle_message(topic: str, message: str):
    if topic == 'chat':
        handle_message_for_chat(message)
    elif topic == 'event':
        handle_message_for_event(message)


def handle_message_for_chat(message: str):
    print(f'chat message: {message}')


def handle_message_for_event(message: str):
    print(f'event message: {message}')


if __name__ == '__main__':
    main()

터미널에서 code 명령어 실행할 수 있도록 설정하는 방법

|

터미널에서 code 명령어 실행할 수 있도록 설정

alias 등을 이용해서 터미널에서 vscode를 실행할 수도 있지만, 아예 vscode 프로그램 내에서 설정하는 방법이 더 깔끔한 것 같습니다.

vscode를 실행한다음 Command + Shift + P를 입력해서 Command Palette를 실행한 다음 shell이라고 입력하면, Shell Command: Install 'code' in PATH를 선택합니다. 그러면 이제 터미널에서 code 명령어를 이용해서 vscode를 실행할 수 있습니다.

M1 오른쪽 Command 키를 한/영 전환키로 맵핑하는 방법

|

오른쪽 Command 키를 한/영 전환키로 맵핑하는 방법

Karabiner-Elements를 이용해서 키맵핑하는 방법입니다. 초반에는 Karabiner가 M1과 충돌이 나서 배터리 광탈 또는 커널 패닉 등의 문제가 있었지만, 지금은 해결된지 오래되었습니다.

Karabiner-Elements여기에서 다운로드 할 수 있습니다.

설치 파일을 다운로드한 다음 설치까지 진행합니다.

Karabiner-Elements 권한 부여

Karabiner-Elements를 실행합니다. 만약 권한이 필요하면 화면과 같이 karabiner-grabberkarabiner-observerInput Monitoring 권한을 부여해줍니다.

image

위 두 항목이 모두 보이지 않을 경우에는 화면에 보이는 항목 하나에서 팝업 메뉴를 실행하면 Show in Finder 메뉴가 출력됩니다.

image

그래도 못 찾으면 아래 경로에서 해당 파일들을 찾을 수 있습니다.

/Library/Application Support/org.pqrs/Karabiner-Elements/bin

또한 아래와 같은 권한도 부여를 해줘야 합니다. System PreferencesSecurity & Privacy를 실행하면 General 탭에서 확인할 수 있습니다.

image

Karabiner-Elements 설정

암튼 권한 부여 후 Karabiner-Elements를 실행합니다. 그리고 다음 그림과 같이 오른쪽 Command 키에 특수한 키를 매핑시킵니다.

image

그런 다음 System Preferences 설정으로 가서 Keyboard 설정을 선택합니다.

image

M1 Homebrew 설치

|

M1 Homebrew 설치

Homebrew 3.0부터 M1(실리콘) MacOS를 지원합니다. 기존에 Homebrew를 설치하는 방법과 동일합니다. 다음 명령어를 이용해서 설치할 수 있습니다.

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

설치 후 다음과 같은 메시지가 출력됩니다.

...

Press RETURN to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R snowdeer:admin /opt/homebrew
==> Downloading and installing Homebrew...
HEAD is now at e970bb187 Merge pull request #12616 from SMillerDev/chore/docs/common_cask_issues
error: Not a valid ref: refs/remotes/origin/master
fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: Could not resolve HEAD to a revision
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/snowdeer/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

설치 후 아래의 Next steps에 있는 두 명령어를 실행해야 brew 명령어를 실행할 수 있습니다.

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/snowdeer/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"