InfraPlatform

CentOS에 Docker 시작하기 - Engine 설치

IT오이시이 2020. 4. 24. 23:23
728x90

리눅스 Docker Engine 설치

 

1. 필요한 패키지 설치

Docker Engine을 설치하려면 yum 저장소 centos-extras저장소를 사용 할 수 있어야 합니다.
overlay2 저장 장치 드라이버를 권장합니다.

CentOs 설치 

# 필요한 패키지 설치
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

# Docker repository 추가
# - CentOs 8 이상
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# - CentOs 8 이상
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 패키지 인덱스 업데이트
sudo dnf makecache

 

Rocky Linux 설치

# 필요한 패키지 설치
sudo dnf install -y yum-utils device-mapper-persistent-data lvm2

# Docker repository 추가
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 패키지 인덱스 업데이트:
sudo dnf makecache

 

2. 이전 버전 Docker 를 제거 합니다.

이전 버전의 Docker는 docker-engine이 설치되어 있으면 관련 종속성과 함께 설치 제거합니다.

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

이전 버전의 Docker엔진은 "docker 이었고, 새로운 버전의 Docker Engine 패키지는 "docker-ce" 입니다.

 

3. Docker 설치

Docker Engine을 다른 방법으로 설치할 수 있습니다

1) Docker의 리포지토리를 설정하고 설치하여 업그레이드 작업을 쉽게 할 수 있습니다.
2) RPM 패키지를 다운로드하여 수동으로 설치 하고 업그레이드를 완전히 수동으로 관리 할 수 있습니다.
3) 자동화 된 스크립트를 사용하여 Docker를 설치 하도록 할 수 있습니다.

 

1) 리포지토리 저장소를 사용하여 설치

리포지토리 설정 유틸리티 yum-utils를 제공 하는 패키지를 설치하고 안정 리포지토리를 yum-config-manager설정

$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

DOCKER ENGINE 설치

# CentOs & Rocky
$ sudo yum install -y docker-ce docker-ce-cli containerd.io

 

특정 버전의 Docker Engine 을 설치하려면 저장소에 사용 가능한 버전을 선택하여 설치 할 수 있습니다.

yum list docker-ce --showduplicates | sort -r
Last metadata expiration check: 0:00:59 ago on Fri 24 Apr 2020 10:00:08 AM EDT.
docker-ce.x86_64            3:19.03.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
Available Packages

 

 

$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

설치시 오류가 발생 하는 경우 아래와 같이 이전 설치 버전을 삭제후
설치하는 법도 중요하다. (종종 이전 버전이 패치되는 경우가 있기 때문이다.)

[삭제]
 yum erase docker-ce docker-ce-cli containerd.io
 
 [설치]
 yum install docker-ce docker-ce-cli containerd.io

 

3. Docker 서비스 실행 및 활성화.

$ sudo systemctl start docker
$ sudo systemctl enable docker

 

4. Docker 그룹에 사용자 추가 (sudo 없이 Docker를 사용하려면 필요)

sudo usermod -aG docker $USER

 

5. hello-world 이미지 를 실행하여 Docker Engine이 올바르게 설치되었는지 확인합니다.

$ sudo docker run hello-world

 

재부팅이나 로그아웃 후 로그인을 하면 Docker를 사용

 

 

DOCKER ENGINE 업그레이드

yum -y upgrade 또는 yum -y install 를 이용하여 패키지를 업그레이드 가능합니다.

 

Docker Engine  제거

  1. Docker Engine, CLI 및 컨테이너 패키지를 설치 제거하십시오.
$ sudo yum remove docker-ce docker-ce-cli containerd.io

2. 호스트의 이미지, 컨테이너, 볼륨 또는 사용자 정의 구성 파일은 자동으로 제거되지 않습니다. 모든 이미지, 컨테이너 및 볼륨을 삭제하려면 다음과 같이 명령 합니다.

$ sudo rm -rf /var/lib/docker

 

 

Linux의 설치 후 단계

루트가 아닌 사용자로 Docker 관리

Docker 데몬은 항상 root사용자로 실행되며, 데몬은 TCP 포트 대신 Unix 소켓에 바인딩됩니다. 기본적으로 Unix 소켓은 사용자가 소유 root하며 다른 사용자는을 sudo 명령을 사용해서 액세스 할 수 있습니다.

sudo 명령으로 docker명령 을 시작하지 않으려면 Unix 그룹을 생성하고 docker사용자를 추가하십시오. Docker 데몬이 시작되면 docker그룹 구성원이 액세스 할 수있는 Unix 소켓을 작성합니다 .

# 1.docker그룹을 만듭니다.
$ sudo groupadd docker

# 2.사용자를 docker그룹에 추가합니다.
$ sudo usermod -aG docker $USER

# 3.Linux에서 다음 명령을 실행하여 그룹 변경 사항을 활성화 할 수도 있습니다.
$ newgrp docker

# 4. sudo 없이 docker 명령을 실행할 수 있는지 확인합니다.
$ docker run hello-world

 

다음과 같은 에러 발생시

WARNING: Error loading config file: /home/user/.docker/config.json - stat /home/user/.docker/config.json: permission denied

이 문제를 해결하려면 ~/.docker/디렉토리 를 제거하거나 (자동으로 다시 작성되지만 사용자 정의 설정이 손실 됨) 다음 명령을 사용하여 소유권과 권한을 변경하십시오.

$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
$ sudo chmod g+rwx "$HOME/.docker" -R

 

 

오류가있는 CentOS 8에서 도커 설치 실패 – containerd.io-1.2.10-3.2.el7.x86_64 패키지 제외

$ sudo yum install docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:13:52 ago on Fri 24 Apr 2020 10:00:08 AM EDT.
Error:
 Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

이 문제를 해결하려면 먼저 containerd.io패키지 를 수동으로 설치해야 합니다.

$ yum install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm

 

$ sudo dnf clean packages

$ sudo yum install docker-ce -y

더보기

The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: Transaction check error:
  file /usr/share/man/man1/docker-attach.1.gz from install of docker-ce-cli-1:19.03.8-3.el7.x86_64 conflicts with file from package podman-manpages-1.4.2-5.module_el8.1.0+237+63e26edc.noarch

다른 버전과 문서 파일 충돌이 일어나는 경우 문서 설치를 제외한다.

$ sudo yum install docker-ce -y --nodocs

 

$ sudo systemctl start docker 
$ sudo docker run hello-world 

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76
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/

728x90
반응형