주요글: 도커 시작하기
반응형

베이그런트(Vagrant)를 이용해서 우분투 설치하기

이 글에서는 단일 노드뿐만 아니라 다중 노드에 도커를 설치하고 실행하는 연습을 하기 위해 아래 환경을 사용한다.

  • 버추얼박스
  • 베이그런트

버추얼박스와 베이그런트를 차례대로 설치한 뒤에는 우분투 단일 노드 환경을 위한 Vagrant 파일을 작업할 폴더에 작성한다. 이 글에서는 E:\vn\vagrant\ubuntu 폴더에 Vagrant 파일을 생성했다고 가정한다.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.network "private_network", ip: "192.168.1.2"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = 2048
    vb.cpus = 2
  end
end

"ubuntu/bionic64"는 우분투 18.04 버전에 해당하는 베이그런트 박스 이미지다. 작업 폴더에서 vagrant up 명령어를 사용해서 우분투 서버를 구동한다.

E:\vm\vagrant\ubuntu>vagrant up
...생략

E:\vm\vagrant\ubuntu>vagrant ssh
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-54-generic x86_64)
...생략

vagrant ssh로 우분투 서버에 접속하고 도커 설치를 위해 root 계정으로 전환한다. "sudo su -" 명령어를 사용해서 root 계정으로 전환할 수 있다.

vagrant@ubuntu-bionic:~$ sudo su -
root@ubuntu-bionic:~#

우분투에 도커 설치하기

https://docs.docker.com/install/linux/docker-ce/ubuntu/ 사이트를 참고해서 우분투에 도커 커뮤니티 버전을 설치한다. 아래는 설치 과정에서 명령어만 정리한 것이다.

도커 리포지토리 설치

apt 패키지 인덱스 업데이트

# apt-get update

apt가 HTTPS 기반 리포지토리 사용하도록 설정

# apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

도커 공식 GPG 키 추가

# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -  
# apt-key fingerprint 0EBFCD88   
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88   
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>   
sub   rsa4096 2017-02-22 [S]

리포지토리 추가

# add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

도커 엔진 설치

apt 패키지 인덱스 업데이트

# apt-get update

도커 설치

# apt-get install docker-ce docker-ce-cli containerd.io

도커 실행 확인(root 계정으로 실행)

root@ubuntu-bionic:~# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:b8ba256769a0ac28dd126d584e0a2011cd2877f3f76e093a7ae560f2a5301c00
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 run 명령어가 어떻게 동작하는지는 뒤에서 설명한다. 일단 지금은 hello-world라는 도커 이미지를 다운로드 받아 실행한다는 정도로만 이해하고 넘어가자.

root 아닌 계정으로 도커 실행하기

docker 명령어는 root 권한을 가진 계정으로 실행해야 한다. 일반 계정은 sudo를 이용해서 docker 명령어를 실행해야 한다. 매번 sudo를 입력하는 귀찮다면 docker 그룹에 사용자를 추가하면 된다. 다음은 현재 사용자를 docker 그룹에 추가하는 명령어 실행 순서를 표시한 것이다. 자세한 내용은 https://docs.docker.com/install/linux/linux-postinstall/ 문서를 참고한다.

  1. 현재 사용자를 docker 그룹에 추가: sudo usermod -aG docker $USER
  2. 그룹 추가를 현재 콘솔에 반영: newgrp docker
  3. 실행 확인: docker run hello-world

관련 글

+ Recent posts