회사에서 개발 중인 솔루션에 DB 연결하는 기능이 있는데, 이 기능을 테스트 하기위해 여러가지 DB가 필요한 상황이다.
기본적으로 PostgreSQL 부터 MySQL, MariaDB, Oracle 도 테스트가 필요했다. (나~~~~ 중에 가능하면 tibero까지!)
원활한 테스트를 위해 데이터 베이스 테스트베드를 구축하기로 하였다. (테스트 베드라는 단어가 적절한건지 모르겠다. 나중에 공부해야지)
각 DB 마다 가상서버를 생성하거나, 한 서버에 DB를 각각 설치하는거 보다는 Docker도 공부할 겸
우분투 가상서버를 하나 만들고 Docker를 설치 한 후에 Docker에 Container로 DB를 설치하는 걸 목표로 하였다.
목표 : 우분투에 도커 설치하고 각각 DB 컨테이너로 올리고 붙는지 테스트 까지 하기
Docker는 이전에 portainer를 이용해서 Container를 구성 했었는데, 이번엔 GUI 없이 최대한~ 명령어를 이용해서 설치 할거다. 그리고 중간중간 궁금한 내용도 채워 넣을 생각이라 내용이 길어질 듯 하다 ㅎ
시간이 없거나 왜 설치하는 지 안 궁금하고 설치만 잘 되면 된다 하는 분들은 굵은글씨를 따라서 쭉쭉 진행하면 될 듯하다.
Ubuntu에 Docker 설치하기
1. putty로 가상서버에 접속한다.
2. 접속 후 docker가 설치 되었는지 확인
docker -v
#혹은
docker info
3. 명령어를 입력하였더니 docker 명령어가 없다고 오류가 나타난다. docker 패키지 설치를 위해 업데이트
* apt-get은 Advanced Packaging Tool의 약자로 리눅스에서 사용되는 패키지 관리 툴
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
* apt-get update -> 현재 운영체제에서 설치가능한 리스트를 업데이트, 사용할 수 있는 패키지와 그 정보를 업데이트
* apt-get upgrade -> update에서 가져온 정보를 토대로 실제로 업데이트 진행
* apt-get dist-upgrade -> 의존성 체크까지 하면서 업그레이드, 위의 업그레이드에서 수행하지 못한 설치가 있을 경우 같이 설치 해줌
4. 도커가 설치되어 있는지 확인하고 설치 되어 있을 경우 삭제
sudo apt-get remove docker docker-engine docker.io containerd runc
* docker랑 docker-engine이랑 docker.io 차이가 뭐야
검색해보니까 docker.io는 데비안 또는 우분트에서 제공하는 패키지 이름이고 docker는 docker.com에서 제공하는 패키지 이름이라고 한다. 빌드되는 것도 다르게 빌드되는데 docker.io 데비안 패키지에서 dependency를 가져오는데, docker는 트리내 밴더 디렉토리에서 dependency를 가져온다고 한다. 자세한 내용은 아래 링크 참조하라는데 뭔소린지 모르겠다 ㅎ 설치하는 방법이 두 가지고 그 차이는 dependency 가져오는데가 다르다는듯 하다.
[docker.io와 docker 차이점 자세한 내용]
https://www.collabora.com/news-and-blog/blog/2018/07/04/docker-io-debian-package-back-to-life/
The docker.io Debian package is back to life
Good news for Debian users: there's now an up-to-date docker.io package in Debian!
www.collabora.com
docker-engine은 docker에서 사용하는 핵심소프트웨어라고 한다. Docker Engine은 다음의 3가지 요소로 구성되어 있다. (공식문서 참고 : https://github.com/docker/docker.github.io/blob/v17.06-release/engine/docker-overview.md#docker-engine)
1) Docker CLI -> 커멘드 라인 도구, 도커 명령을 실행함 ex) docker build, docker run 등등
2) Docker Engine API -> CLI에 입력된 커멘드에 따라 호출되는 API
3) Docker 데몬 -> 리눅스 데몬 프로세스에서 API가 호출되는것을 기다렸다가, 호출된 API를 수행함.
5. docker 설치에 필요한 패키지 설치 및 업데이트
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
* 그래서 뭐 설치 하는건데?
1) apt-transport-https -> 패키지 관리자가 https로 저장소에 접근가능하도록 함.
[Error] The Following Package Is Needed By The Script, But Not Installed: Apt-Transport-Https” 오류가 발생할 경우 sudo apt-get install 로 설치하여 해결가능!
2) ca-certificates -> CA 인증기관에서 발급한 디지털 인증서로 SSL 클라이언트의 서명을 확인할 수 있음. (어렵다. SSL 서버 접근을 위해 설치하는거로 생각하고 넘어가자)
A CA certificate is a digital certificate issued by a certificate authority (CA), so SSL clients (such as web browsers) can use it to verify the SSL certificates sign by this CA. For example, stackoverflow.com uses Let's Encrypt to sign its servers, and SSL certificates send by stackoverflow.com mention they are signed by Let's Encrypt. Your browser contains the CA certificate from Let's Encrypt and so the browser can use that CA certificate to verify the stackoverflow's SSL certificate and make sure you are indeed talking to real server, not man-in-the-middle. https://security.stackexchange.com/a/20833/233126 provides a more detail explanation about how TLS/SSL certificates work.
3) curl -> 데이터 다운용
* wget으로 다운로드 받을 수 있지만 curl이 지원하는 프로토콜도 많고 더 다양하게 지원
자세한 내용은 : https://daniel.haxx.se/docs/curl-vs-wget.html
4) gnupg-agent -> ssh-agent랑 비슷하게 GnuPg Key를 관리하는 agent 데비안 계열 시스템에서 설치하여 이용
* GnuPG Keys -> GNU Privacy Guard 로 리눅스 통신시 보안을 위한 도구, 데이터를 암호와하고 전자 서명을 만들고 PGP를 대신하여 암호화 도구로 사용 가능
5) software-properties-common -> PPA(Personal Package Archive) 사용을 위해 설치
*PPA : apt-get에서 다운로드 할 수 있는 패키지의 버전이 최신이 아닐 수 도있음. PPA는 개발자가 소스 코드를 입력하면 자동으로 패키지화하여 사용자가 바로 다운로드 받을 수 있게 함.
6. docker 공식 GPG key 추가
* 왜 docker는 gpg key를 추가해야하나
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
7. docer 설치 repository 추가
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
8. docker 엔진과 docker containerd 설치
sudo apt-get install docker-ce docker-ce-cli containerd.io
9. docker info로 설치 확인
docker info
* Server 에 아래 문구 처럼 permission denied 에러 뜨는 경우 -> 데몬 소켓에 권한이 없어서 발생하는 오류
got permission denied while trying to connect to the docker daemon socket at unix:///var/run/docker.sock: get "http://%2fvar%2frun%2fdocker.sock/v1.24/info": dial unix /var/run/docker.sock: connect: permission denied
# Server permission denied 에러 해결 명령어
sudo chmod 666 /var/run/docker.sock
맨 아래 WARNING: No swap limit support 경고 -> 스왑 메모리 제한이 없어서 생기는 오류
* 스왑 메모리 : Ram 용량이 가득 찼을 경우 데이터 손실이 일어나거나 문제가 발생할 수 있음, 이를 방지 하기 위해 Swap 메모리 영역을 미리 정의 (비상 시 대비하기위해)
10. docker 시스템 확인 -> Active: active (running) 면 성공!
sudo systemctl status docker
* systemctl -> RHEL7에 도입된 systemd를 관리하는 명령어로 .service 파일을 이 명령어로 제어 가능
* systemd -> 모든 프로세스들을 관리하는 init 시스템으로 뒤에 d는 daemon
11. 테스트 이미지 다운로드
sudo docker pull hello-world
* docker pull -> 도커의 레지스트리에서 리포지토리 또는 이미지를 가져올 수 있음. 이미지 확인은 sudo docer images로 확인 가능
https://docs.docker.com/engine/reference/commandline/pull/
12. 테스트 이미지 띄우기
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/
13. 도커에 띄워져있는 컨테이너 확인
sudo docker ps -a
* docker ps -> 가장 기초적인 명령어로 컨테이너의 리스트를 반환, 옵션이 없을 시 현재 가동중인 리스트만, -a 옵션을 추가하면 기동중, 멈춘 컨테이너 모두 반환
14. 기동 확인 후 테스트 컨테이너 삭제
sudo docker rm 테스트 컨테이너 ID
다음 게시글에서는 설치된 docker에 postgreSQL를 깔아보도록 하겠다.