Linux에 Docker 컨테이너를 설치하는 방법은 무엇입니까? (우분투 및 CentOS)
게시 됨: 2019-08-01 Docker는 의심할 여지 없이 기업 및/또는 개인 프로젝트 요구 사항을 위한 최고의 Container Management Platform
입니다.
Docker가 필요한 이유는 무엇입니까?
프로젝트에 대해 이 간단한 시나리오를 고려하십시오.
- 50개 이상의 maven 종속성이 있는 복잡한 Java Enterprise 애플리케이션이 있습니다.
- 로컬 서비스 종속성이 거의 없습니다.
- 로컬에서 실행 중인 자체 데이터베이스 인스턴스가 있습니다.
- 환경을 설정하는 데 필요한 사용자 지정 셸 스크립트가 10개 이상 있습니다.
- ~5개의 환경 변수가 있습니다.
- ~5개의 자동 시작 스크립트가 있습니다.
- 등등…
위의 모든 것을 고객에게 배송하려면 많은 단계를 거쳐야 합니다. 그렇지 않아?
그것이 Docker가 등장하는 곳입니다.
간단:
위의 모든 것을 single docker image
로 구축 및 조립하고 해당 이미지를 고객에게 배송하는 것은 어떻습니까? 클라이언트를 위한 single step install
로 get ready within few minutes
있습니다.
이 자습서에서는 install Docker on Linux
하는 방법과 필요한 모든 단계에 대해 설명합니다.
시작하자:
1 단계. Linux 호스트에 로그인하고 전제 조건 확인
Docker는 3가지 버전으로 제공됩니다.
- 도커 엔진 – 커뮤니티
- 도커 엔진 – 엔터프라이즈
- 도커 엔터프라이즈
이 자습서에서는 Docker Community Edition
설치 단계를 살펴보겠습니다.
1.1) Linux 호스트에 로그인합니다.
내 Linux 호스트로 Digital Ocean droplet을 사용하고 있습니다.
1 2 3 |
bash - 3.2 $ ssh root @ 45.56.94.4 root @ 45.56.94.4 ' s password : Welcome to Ubuntu 19.04 ( GNU / Linux 5.0.0 - 13 - generic x86_64 ) |
1.2) Linux OS 아키텍처 확인:
64-bit
아키텍처가 필요합니다.
1 2 3 |
root @ localhost : ~ # arch x86_64 |
1.3) Linux OS 커널 레벨 확인:
커널 레벨은 3.0보다 커야 합니다.
1 2 3 |
root @ localhost : ~ # uname -r 5.0.0 - 13 - generic |
2 단계. 도커 커뮤니티 에디션 설치
2.1) Docker의 공식 PGP 키를 시스템에 추가해야 합니다.
1 2 3 4 |
root @ localhost : ~ # curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - OK root @ localhost : ~ # |
2.2) PGP 키가 올바른지 확인하십시오.
1 2 3 4 |
root @ localhost : ~ # sudo apt-key fingerprint 0EBFCD88 | grep 5822 Warning : apt - key output should not be parsed ( stdout is not a terminal ) 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 |
2.3) Ubuntu OS를 최신 버전으로 설치해야 합니다.
Command:
sudo apt-get update
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
root @ localhost : ~ # sudo apt-get update Hit : 1 http : //mirrors.linode.com/ubuntu disco InRelease Get : 2 http : //mirrors.linode.com/ubuntu disco-updates InRelease [97.5 kB] Get : 3 http : //mirrors.linode.com/ubuntu disco-backports InRelease [88.8 kB] Hit : 4 https : //download.docker.com/linux/ubuntu disco InRelease Get : 5 http : //mirrors.linode.com/ubuntu disco-updates/main amd64 Packages [226 kB] Get : 6 http : //security.ubuntu.com/ubuntu disco-security InRelease [97.5 kB] Get : 7 http : //mirrors.linode.com/ubuntu disco-updates/main i386 Packages [194 kB] Get : 8 http : //mirrors.linode.com/ubuntu disco-updates/universe i386 Packages [252 kB] Get : 9 http : //mirrors.linode.com/ubuntu disco-updates/universe amd64 Packages [254 kB] Get : 10 http : //mirrors.linode.com/ubuntu disco-updates/universe Translation-en [80.1 kB] Get : 11 http : //security.ubuntu.com/ubuntu disco-security/main i386 Packages [144 kB] Get : 12 http : //security.ubuntu.com/ubuntu disco-security/main amd64 Packages [173 kB] Get : 13 http : //security.ubuntu.com/ubuntu disco-security/universe amd64 Packages [220 kB] Get : 14 http : //security.ubuntu.com/ubuntu disco-security/universe i386 Packages [217 kB] Get : 15 http : //security.ubuntu.com/ubuntu disco-security/universe Translation-en [55.4 kB] Fetched 2 , 098 kB in 2s ( 1 , 188 kB / s ) Reading package lists . . . Done |
2.4) 안정적인 최신 Docker Repository 설정
Command:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) 안정"
1 2 3 4 5 6 7 8 |
root @ localhost : ~ # sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" Hit : 1 http : //mirrors.linode.com/ubuntu disco InRelease Hit : 2 http : //mirrors.linode.com/ubuntu disco-updates InRelease Hit : 3 http : //mirrors.linode.com/ubuntu disco-backports InRelease Hit : 4 https : //download.docker.com/linux/ubuntu disco InRelease Hit : 5 http : //security.ubuntu.com/ubuntu disco-security InRelease Reading package lists . . . Done |
2.5) 도커 설치
Command:
sudo apt-get install docker-ce
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
root @ localhost : ~ # sudo apt-get install docker-ce Reading package lists . . . Done Building dependency tree Reading state information . . . Done The following packages were automatically installed and are no longer required : bridge - utils dns - root - data dnsmasq - base ubuntu - fan Use 'sudo apt autoremove' to remove them . The following additional packages will be installed : aufs - tools containerd . io docker - ce - cli libltdl7 The following packages will be REMOVED : containerd docker . io runc The following NEW packages will be installed : aufs - tools containerd . io docker - ce docker - ce - cli libltdl7 0 upgraded , 5 newly installed , 3 to remove and 101 not upgraded . Need to get 87.9 MB of archives . After this operation , 133 MB of additional disk space will be used . Do you want to continue ? [ Y / n ] Y Get : 1 http : //mirrors.linode.com/ubuntu disco/universe amd64 aufs-tools amd64 1:4.9+20170918-2 [104 kB] Get : 2 http : //mirrors.linode.com/ubuntu disco/main amd64 libltdl7 amd64 2.4.6-10 [38.3 kB] Get : 3 https : //download.docker.com/linux/ubuntu disco/stable amd64 containerd.io amd64 1.2.6-3 [22.6 MB] Get : 4 https : //download.docker.com/linux/ubuntu disco/stable amd64 docker-ce-cli amd64 5:19.03.1~3-0~ubuntu-disco [42.5 MB] Get : 5 https : //download.docker.com/linux/ubuntu disco/stable amd64 docker-ce amd64 5:19.03.1~3-0~ubuntu-disco [22.7 MB] Fetched 87.9 MB in 3s ( 34.9 MB / s ) ( Reading database . . . 83080 files and directories currently installed . ) Removing docker . io ( 18.09.5 - 0ubuntu1 ) . . . '/usr/share/docker.io/contrib/nuke-graph-directory.sh' - > '/var/lib/docker/nuke-graph-directory.sh' Removing containerd ( 1.2.6 - 0ubuntu1 ) . . . Removing runc ( 1.0.0 ~ rc7 + git20190403 . 029124da - 0ubuntu1 ) . . . Selecting previously unselected package aufs - tools . ( Reading database . . . 82836 files and directories currently installed . ) Preparing to unpack . . . / aufs - tools_1 % 3a4.9 + 20170918 - 2_amd64.deb . . . Unpacking aufs - tools ( 1 : 4.9 + 20170918 - 2 ) . . . Selecting previously unselected package containerd . io . Preparing to unpack . . . / containerd . io_1 . 2.6 - 3_amd64.deb . . . Unpacking containerd . io ( 1.2.6 - 3 ) . . . Selecting previously unselected package docker - ce - cli . Preparing to unpack . . . / docker - ce - cli_5 % 3a19.03.1 ~ 3 - 0 ~ ubuntu - disco_amd64 . deb . . . Unpacking docker - ce - cli ( 5 : 19.03.1 ~ 3 - 0 ~ ubuntu - disco ) . . . Selecting previously unselected package docker - ce . Preparing to unpack . . . / docker - ce_5 % 3a19.03.1 ~ 3 - 0 ~ ubuntu - disco_amd64 . deb . . . Unpacking docker - ce ( 5 : 19.03.1 ~ 3 - 0 ~ ubuntu - disco ) . . . Selecting previously unselected package libltdl7 : amd64 . Preparing to unpack . . . / libltdl7_2 . 4.6 - 10_amd64.deb . . . Unpacking libltdl7 : amd64 ( 2.4.6 - 10 ) . . . Setting up aufs - tools ( 1 : 4.9 + 20170918 - 2 ) . . . Setting up containerd . io ( 1.2.6 - 3 ) . . . Setting up libltdl7 : amd64 ( 2.4.6 - 10 ) . . . Setting up docker - ce - cli ( 5 : 19.03.1 ~ 3 - 0 ~ ubuntu - disco ) . . . Setting up docker - ce ( 5 : 19.03.1 ~ 3 - 0 ~ ubuntu - disco ) . . . Installing new version of config file / etc / init . d / docker . . . Installing new version of config file / etc / init / docker . conf . . . Created symlink / etc / systemd / system / multi - user . target . wants / docker . service → / lib / systemd / system / docker . service . Processing triggers for systemd ( 240 - 6ubuntu5 ) . . . Processing triggers for man - db ( 2.8.5 - 2 ) . . . Processing triggers for libc - bin ( 2.29 - 0ubuntu2 ) . . . |

2.6) Docker 버전 확인
1 2 |
root @ localhost : ~ # docker -v Docker version 19.03.1 , build 74b1e89 |
3단계. Docker 시작 및 Hello World 실행
3.1) Linux에서 Docker를 실행하는 간단한 명령
설치 중에 위에서 볼 수 있듯이 Docker는 시스템 서비스로 자신을 등록합니다: /lib/systemd/system/docker.service
.
1 |
root @ localhost : ~ # sudo systemctl start docker |
3.2) Hello World Docker를 가져와서 실행해보자.
Command:
sudo docker run hello-world
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
root @ localhost : ~ # sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest : Pulling from library / hello - world 1b930d010525 : Pull complete Digest : sha256 : 6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f 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/ root @ localhost : ~ # |
위의 명령은 docker 이미지를 가져오고 Docker Hello World 응용 프로그램을 실행할 수 있습니다.
4단계. Docker 이미지/리포지토리를 확인하는 방법은 무엇입니까?
Hello World 앱을 실행하기 전에:
1 2 3 4 5 6 |
root @ localhost : ~ # docker images REPOSITORY TAG IMAGE ID CREATED SIZE keyansoftwares / logviewersvc latest 04612d6a457d 2 months ago 144MB keyansoftwares / logreadagent latest 0385a757deb5 2 months ago 138MB keyansoftwares / logreadagent < none > d75a02abb278 2 months ago 369MB grafana / grafana latest f96bf1723e2a 3 months ago 245MB |
Hello World 앱을 실행한 후:
여기에서 볼 수 있듯이 아래에 새로운 저장소 hello-world가 표시됩니다.
1 2 3 4 5 6 7 |
root @ localhost : ~ # docker images REPOSITORY TAG IMAGE ID CREATED SIZE keyansoftwares / logviewersvc latest 04612d6a457d 2 months ago 144MB keyansoftwares / logreadagent latest 0385a757deb5 2 months ago 138MB keyansoftwares / logreadagent < none > d75a02abb278 2 months ago 369MB grafana / grafana latest f96bf1723e2a 3 months ago 245MB hello - world latest fce289e99eb9 7 months ago 1.84kB |
축하합니다. 당신 준비 다 됐어요. Docker용 Linux 환경을 설정하고 Docker를 설치하고 첫 번째 Docker 애플리케이션도 실행했습니다.
추가 단계:
다음 설치 후 단계를 따르는 것이 좋습니다.
VM 재부팅 후 도커를 자동으로 시작하는 방법은 무엇입니까?
Command:
sudo systemctl enable docker
1 2 3 4 |
root @ localhost : ~ # sudo systemctl enable docker Synchronizing state of docker . service with SysV service script with / lib / systemd / systemd - sysv - install . Executing : / lib / systemd / systemd - sysv - install enable docker |
위의 명령을 실행하기만 하면 다음에 VM/호스트를 재부팅할 때 도커가 자동으로 시작됩니다.
위 명령을 실행하는 데 문제가 있거나 Docker 문제가 있으면 알려주십시오.
CentOS에 Docker를 설치하고 싶으십니까?
위 Step-2
를 아래 단계로 바꾸세요.
1 2 3 4 5 6 7 8 9 |
root @ localhost : ~ # sudo yum install -y yum-utils device-mapper-persistent-data lvm2 root @ localhost : ~ # sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo root @ localhost : ~ # sudo yum install docker-ce docker-ce-cli containerd.io root @ localhost : ~ # sudo systemctl start docker root @ localhost : ~ # sudo docker run hello-world |