Homebrew에서 macOS에 Docker 설치하기 Hello world

Homebrew에서 macOS에 Docker 설치하기 Hello world

2022-10-06 last update

5 minutes reading MacOSX 도커 homebrew HelloWorld

개요


  • Homebrew에서 macOS에 Docker 설치
  • Docker가 공식적으로 제공하는 hello-world 이미지를 다운로드하여 컨테이너를 만들고 시작합니다.

    환경


  • macOS Mojave

  • Homebrew에서 Docker 설치


    $ brew cask install docker
    ==> Satisfying dependencies
    ==> Downloading https://download.docker.com/mac/stable/37199/Docker.dmg
    ######################################################################## 100.0%
    ==> Verifying SHA-256 checksum for Cask 'docker'.
    ==> Installing Cask docker
    ==> Moving App 'Docker.app' to '/Applications/Docker.app'.
    🍺  docker was successfully installed!
    

    설치했지만 docker 명령을 찾을 수 없습니다.


    $ docker --version
    -bash: docker: command not found
    

    Docker.app 시작



    Docker.app를 시작하면 docker 명령을 사용할 수 있습니다.
    $ open /Applications/Docker.app
    

    Docker ID는 필요하지 않으면 생성하지 않아도됩니다.



    "Docker Desktop is now up and running!"

    이제 docker 명령을 사용할 수 있습니다.
    $ docker --version
    Docker version 19.03.1, build 74b1e89
    
    $ which docker
    /usr/local/bin/docker
    
    $ ls -la /usr/local/bin/docker
    lrwxr-xr-x  1 root  admin  54  8  9 09:44 /usr/local/bin/docker -> /Applications/Docker.app/Contents/Resources/bin/docker
    

    설치된 Docker 정보



    인스톨 되는 Docker 의 버젼 등은 Homebrew Cask 의 소스 코드에 실려 있다.

    homebrew-cask/docker.rb at 5037705e8ed028ae1a45c6fb7d6b94e5fb0cc8d8 · Homebrew/homebrew-cask · GitHub
      if MacOS.version <= :el_capitan
        version '18.06.1-ce-mac73,26764'
        sha256 '3429eac38cf0d198039ad6e1adce0016f642cdb914a34c67ce40f069cdb047a5'
      else
        version '2.1.0.1,37199'
        sha256 'b638696702d88308a49c5ff985055b6bb329afcfcd0c3ffda1c3fed6e078d01a'
      end
    

    Docker 공식 Hello world 실행



    Docker가 공식적으로 제공하는 hello-world 이미지가 있습니다.

    hello-world - Docker Hub

    Docker Official Images
    Hello World! (an example of minimal Dockerization)

    docker run으로 hello-world 이미지를 다운로드하고 이미지에서 새 컨테이너를 만들고 시작하면 메시지가 표시됩니다.
    $ docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    1b930d010525: Pull complete 
    Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
        (amd64)
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/
    

    docker images로 만든 Docker 이미지 목록을 확인합니다.
    $ docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    hello-world         latest              fce289e99eb9        7 months ago        1.84kB
    

    docker ps -a로 컨테이너 목록을 표시합니다.
    $ docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
    f2d8db4444fa        hello-world         "/hello"            7 minutes ago       Exited (0) 7 minutes ago                       pensive_chaum
    

    docker rm 으로 컨테이너 ID를 지정해 컨테이너를 삭제.
    $ docker rm f2d8db4444fa
    f2d8db4444fa
    

    참고 자료


  • Docker를 Homebrew에서 Mac OS에 배포하는 방법 - Qiita
  • How to Install Docker on macOS using Homebrew
  • 명령줄 참조 — Docker-docs-ko 17.06.Beta 문서