DevOps

[Docker] Mac에서 brew로 docker 설치하기

📝 작성 : 2020.07.18  ⏱ 수정 : 
728x90

brew cask가 dedeprecated되고 그냥 brew install로 설치할 수 있도록 변경되었습니다.(--cask옵션을 줘도 됩니다.)

 

$ brew install docker docker-machine
$ brew install virtualbox
-> System Preference > Security & Privacy > Allow

$ docker-machine create --driver virtualbox default
$ docker-machine env default
$ eval $(docker-machine env default)

$ docker run hello-world
$ docker-machine stop default

 

brew 설치법은 여기에서 확인하실 수 있습니다.

단순히 brew install docker 한 후 도커를 run하면 아래와 같은 오류가 발생합니다.

 

$ docker run hello-world

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

 

이유는 방금 설치한 docker는 macOS에서 단순 클라이언트 뿐입니다. Docker데몬은 Linux 관련 커널 기능을 사용하기 때문에 macOS에서는 기본적으로 Docker를 사용할 수 없습니다. 그래서 docker-machine을 통해 VM을 생성하고 연결합니다.

 

$ brew install docker-machine
$ brew install virtualbox

 

virtualbox를 다운로드 받다보면 아래와 같은 오류가 발생하고 설치가 제대로 되지 않습니다.

 

System Preference > Security & Privacy에 가면 사진과 같은 메시지가 떠있을 텐데 Allow해줍니다.

 

docker-machine ls 명령어를 입력해보고 아래와 같은 경우라면 virtualbox를 다시 설치하고 VM을 생성합니다.

 

$ docker-machine ls 

NAME      ACTIVE   DRIVER       STATE     URL   SWARM   DOCKER    ERRORS
default   -        virtualbox   Stopped                 Unknown

 

PS. VM을 생성하는 부분에서도 아래와 같은 오류가 발생했을 것 입니다.

 

$ docker-machine create --driver virtualbox default

[...]
(default) Progress state: NS_ERROR_FAILURE
(default) VBoxManage: error: Failed to create the host-only adapter
(default) VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
(default) VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
[...]

 

 

$ brew install virtualbox
$ docker-machine create --driver virtualbox default
$ docker-machine ls 

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER      ERRORS
default   -        virtualbox   Running   tcp://192.168.xxx.xxx:xxxx         v19.03.12

docker-machine env default라고 치면 아래와 같이 떴는데 아마 저는 zsh쉘을 써서 저렇게 뜬 것 같습니다.

$ docker-machine env default

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.xxx.xxx:xxxx"
export DOCKER_CERT_PATH="/Users/dhlee/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)

 

docker-machine에서 말한대로 eval $(docker-machine env default) 명령어를 입력합니다.

 

$ eval $(docker-machine env default)
$ docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
[...]

docker run hello-world를 했을 때 위와 같이 나오면 제대로 설치 된 것입니다.

반응형

'DevOps' 카테고리의 다른 글

[Docker] docker 컨테이너, 이미지 삭제  (0) 2020.07.19