뉴질랜드 다이어리(NZ Diary) 라빠

Docker 따라하기 #1 본문

개발

Docker 따라하기 #1

Donochi 2019. 9. 4. 08:47

1년전쯤 잠시 공부하며 실습해보다가 완전 잊고 지냈던 Docker.
여러 블로거 분들의 글을 보며 다시한번 공부하면서 정리해 보려 한다.

우선 알아두어야 할것은 Docker 를 Host Os 에 바로 설치할 수도 있지만, 실전에서 Docker 를 사용하게될 Host Os 와 개발/개인/실습 Host Os 가 다르므로, 실전에서 사용할 OS(주로 Linux)에서 실습을 진행하기 위해 Vagrant + VirtualBox 를 사용하는것이다.
즉, 실습 Os 가 Linux 라면 굳이 Vagrant + VirtualBox 를 이용하지 않고, 바로 Docker 를 설치하여도 된다. 다만, 같은 Linux 라 하더라도, 여러 종류와 버전이 있으니, 옵션정도로 생각하면 될것 같다.

VirtualBox 및 Vagrant 설치

  • VirtualBox 설치

VirtualBox for OS X Host

  • Vagrant 설치

Vagrant for macOS

$ vagrant -v
Vagrant 2.2.3

Guest Os 설정 및 구동

Vigrant.conf 파일의 아래 부분을 수정/언코멘트만 해주시면 됩니다.

config.vm.box = "centos/7"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network "forwarded_port", guest: 80, host: 8080

구동 영상은 녹화했다가 시간이 너무 오래 걸려서, 결과로 대신합니다

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'centos/7' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'centos/7'
    default: URL: https://vagrantcloud.com/centos/7
==> default: Adding box 'centos/7' (v1901.01) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/1901.01/providers/virtualbox.box
    default: Download redirected to host: cloud.centos.org
==> default: Successfully added box 'centos/7' (v1901.01) for 'virtualbox'!
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '1901.01' is up to date...
==> default: Setting the name of the VM: centos7_default_1551223782426_14500
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 (guest) => 8080 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default: 
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /Users/dongho/Dev/centos7/ => /vagrant

구동이 정상적이라면, 아래와 같이 VM 에 접근할 수 있습니다.

결과

Docker 설치

여기서부터는 Host Os 가 아닌, Guest Os 에서 진행합니다. 즉, vagrang ssh 상에서 진행한다고 생각하시면 됩니다. 이렇게 하면, Guest Os 에 Docker 가 설치되어 문제가 발생했을때 처리가 쉬워지고, 실전에서 사용하는것처럼 Docker 를 사용해 볼 수 있습니다. ;)

Docker 설치는 아래의 두가지 방법중 한가지를 따라하시면 됩니다.

자동 설치

직접 설치

설치가 정상적이라면, 아래와 같이 확인이 가능합니다.

결과

'개발' 카테고리의 다른 글

Docker 따라하기 #3  (0) 2019.09.04
Docker 따라하기 #2  (0) 2019.09.04
최근 수개월동안 새로 공부하고 있는 기술들...  (0) 2017.03.08
Web Scrapping with Python, PHP, Javascript  (0) 2017.02.13
[C#] Nullable type 의 사용방법  (0) 2016.11.29