[Docker] 00 Ubuntu 20.04 Docker 설치하기
Ubuntu 20.04(LTS) Docker 설치
오랜만에 Docker를 다시 설치하면서 내용을 간단하게 정리해보고자 한다.
Docker 란..?
간단히 말하자면, Docker는 container 에서 application process들을 관리하는 process를 단순화하는 application이다. Container를 사용하면 리소스를 격리한 프로세스에서 application을 실행할 수 있다. Anaconda 등과 같은 가상환경 시스템과 비슷하지만 container는 더 portable하고 리소스-친화적이며, host OS에 더 의존적이다.
Docker container에 대한 좀더 구체적인 개념을 원한다면 The Docker Ecosystem: An Introduction to Common Components 를 읽어보자.
Prerequisites
Docker Engine 을 설치할 환경으로 나는 64-Bit 버전의 Ubuntu 20.04(LTS)를 준비했다.
Uninstall old versions
새 버전의 Docker 를 설치하기 위해서는 이전에 설치한 Docker 관련 모든 패키지들을 삭제하는 것이 좋다.
예를 들면, docker, docker.io, docker-engine 과 같은 이전 버전의 Docker.
$ sudo apt-get remove docker docker-engine docker.io containerd runc
위 명령어를 쳤을 때, "none of these packeges are installed" 라고 뜨면 된다.
Uninstall Docker Engine
1. Docker Engine, CLI, Containerd, Docker Cpmpose 패키지들을 삭제한다.
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin
2. Images, Containers, Volumes 혹은 configuration files들은 자동으로 지워지지 않는다. 이들을 삭제하려면,
$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd
*수정했던 configuration file들은 꼭 수동으로 지워야한다.
Install using the repository
만약 저처럼 처음 받는 경우에는 Docker repository를 set up 해줘야한다. 이렇게 해야 Docker 설치와 업데이트에 문제가 없다.
Set up the repository
1. HTTPS를 통해 repository를 사용할 수 있도록 적절한 패키지 인덱스를 업데이트하고, 필요 피키지들을 설치한다.
$ sudo apt-get update
$ sudo apt-get install ca-certificates curl gnupg lsb-release
2. Docker의 공식적인 GPG key를 host local에 추가한다.
$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
3. 아래의 명령어로 repository 를 set up 한다.
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine
1. Repository set up 이후에는 apt package index를 업데이트 해준 다음, 최신 버전의 Docker Engine, containerd, Docker Compose를 설치해준다.
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# if Receiving GPG error when sudo apt-get update
$ sudo chomod a+r /etc/apt/keyrings/docker.gpg
2. 혹시 특정 버전의 Docker Engine을 설치하고자 한다면, repo. 에서 설치가능한 버전을 찾아 설치하면 된다.
a. 아래의 명령어로 검색 한뒤 원하는 버전으로 설치 진행
# search version
$ apt-cache madison docker-ce
# install
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io docker-compose-plugin
3. Docker Engine 이 제대로 설치 되었다면 hello-world image를 돌려보는 예제를 통해 확인해보자.
$ sudo service docker start
$ sudo docker run hello-world
'''
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/
'''
위와 같이 문구가 출력될 경우 제대로 설치한 것이다. 만약, 에러가 난다면, 다시 삭제하고 설치해보자!