-
Docker 컨테이너 Centos에 설치하기Programming and Database/Docker And Kubernetes 2024. 1. 29. 22:48728x90반응형
Docker 컨테이너 Centos에 설치하기
※ 컨테이너 기반의 Docker 서비스를 구축하기 위한 사전 준비 사항
01. Docker#1 / Host IP: 127.0.0.1 / Host 포트: 105 / Guest IP: 10.100.0.105 / Guest 포트: 22
02. Docker#2 / Host IP: 127.0.0.1 / Host 포트: 106 / Guest IP: 10.100.0.106 / Guest 포트: 22
03. Docker 설치
- URL: https://docs.docker.com[root@docker-centos ~]# yum install -y yum-utils Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.kakao.com * extras: mirror.kakao.com * updates: mirror.kakao.com base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version Nothing to do
▶ Centos가 설치된 VM에서 yum 명령어를 통한 yum-utils를 설치합니다. already installed and latest version
Nothing to do라고 이미 설치된 있다는 경고문이 출력되면 이미 설치가 되어 있는 상태로 별도의 설치가 필요하지 않습니다.[root@docker-centos ~]# yum-config-manager \ > --add-repo \ > https://download.docker.com/linux/centos/docker-ce.repo Loaded plugins: fastestmirror, langpacks adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo
▶ yum-config-manager를 통해서 Repository URL을 등록합니다. Docker docs SET UP THE REPOSITORY 가이드에는 해당 URL을 등록하라고 되어있습니다.(https://download.docker.com/linux/centos/docker-ce.repo)
[root@docker-centos ~]# yum install -y docker-ce docker-ce-cli containerd.io Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.kakao.com * extras: mirror.kakao.com * updates: mirror.kakao.com docker-ce-stable | 3.5 kB 00:00:00 (1/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00 (2/2): docker-ce-stable/7/x86_64/primary_db | 104 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package containerd.io.x86_64 0:1.6.20-3.1.el7 will be installed --> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.6.20-3.1.el7.x86_64 ...(생략) --> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64 ---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed --> Running transaction check ---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================================================= Installing: containerd.io x86_64 1.6.20-3.1.el7 docker-ce-stable 34 M docker-ce x86_64 3:23.0.4-1.el7 docker-ce-stable 23 M docker-ce-cli x86_64 1:23.0.4-1.el7 docker-ce-stable 13 M Installing for dependencies: container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k docker-buildx-plugin x86_64 0.10.4-1.el7 docker-ce-stable 12 M docker-ce-rootless-extras x86_64 23.0.4-1.el7 docker-ce-stable 8.8 M docker-compose-plugin x86_64 2.17.2-1.el7 docker-ce-stable 12 M fuse-overlayfs x86_64 0.7.2-6.el7_8 extras 54 k fuse3-libs x86_64 3.6.1-4.el7 extras 82 k slirp4netns x86_64 0.4.3-4.el7_8 extras 81 k Transaction Summary ============================================================================================================================================================================================= Install 3 Packages (+7 Dependent packages) Total download size: 103 M Installed size: 367 M Downloading packages: (1/10): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00 warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY9 MB/s | 21 MB 00:00:13 ETA Public key for docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm is not installed (2/10): docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm | 12 MB 00:00:02 (3/10): docker-ce-23.0.4-1.el7.x86_64.rpm | 23 MB 00:00:04 ..(생략) | 82 kB 00:00:00 (9/10): docker-ce-rootless-extras-23.0.4-1.el7.x86_64.rpm | 8.8 MB 00:00:02 (10/10): docker-compose-plugin-2.17.2-1.el7.x86_64.rpm | 12 MB 00:00:01 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 9.3 MB/s | 103 MB 00:00:11 Retrieving key from https://download.docker.com/linux/centos/gpg Importing GPG key 0x621E9F35: Userid : "Docker Release (CE rpm) <docker@docker.com>" Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35 From : https://download.docker.com/linux/centos/gpg Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 1/10 Installing : containerd.io-1.6.20-3.1.el7.x86_64 2/10 Installing : docker-compose-plugin-2.17.2-1.el7.x86_64 3/10 Installing : slirp4netns-0.4.3-4.el7_8.x86_64 4/10 ...(생략) 4/10 Verifying : 3:docker-ce-23.0.4-1.el7.x86_64 5/10 Verifying : slirp4netns-0.4.3-4.el7_8.x86_64 6/10 Verifying : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 7/10 Verifying : docker-ce-rootless-extras-23.0.4-1.el7.x86_64 8/10 Verifying : containerd.io-1.6.20-3.1.el7.x86_64 9/10 Verifying : docker-compose-plugin-2.17.2-1.el7.x86_64 10/10 Installed: containerd.io.x86_64 0:1.6.20-3.1.el7 docker-ce.x86_64 3:23.0.4-1.el7 docker-ce-cli.x86_64 1:23.0.4-1.el7 Dependency Installed: container-selinux.noarch 2:2.119.2-1.911c772.el7_8 docker-buildx-plugin.x86_64 0:0.10.4-1.el7 docker-ce-rootless-extras.x86_64 0:23.0.4-1.el7 docker-compose-plugin.x86_64 0:2.17.2-1.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8 Complete!
▶ Ubuntu OS에서 설치한 것과 같이 Centos에서도 동일한 패키지 docker-ce, docker-ce-cli, containerd.io 패키지를 설치합니다.
* docker-ce : Docker CE 패키지(Docker Engine)
* docker-ce-cli : Docker CLI 패키지
* containerd.io : ctr(디버깅 목적으로만 사용, 기능 제한적) +nerdctl(도커명령어 포함)[root@docker-centos ~]# systemctl start docker [root@docker-centos ~]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since 금 2023-04-21 23:50:29 KST; 5s ago Docs: https://docs.docker.com Main PID: 2365 (dockerd) Tasks: 8 Memory: 28.8M CGroup: /system.slice/docker.service └─2365 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
▶ Centos의 경우 systemctl 명령어를 통해 Docker 서비스를 기동 해주고 상태체크 확인을 통해 Active 상태인지를 확인합니다.
[root@docker-centos ~]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
▶ 재기동시 Docker 서비스가 자동으로 실행될 수 있도록 systemctl enable docker 명령어를 통해서 적용시켜 줍니다.
[root@docker-centos ~]# ps -ef | grep -i docker avahi 742 1 0 23:43 ? 00:00:00 avahi-daemon: running [docker-centos.local] root 2365 1 1 23:50 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock root 2517 2130 0 23:50 pts/0 00:00:00 grep --color=auto -i docker
▶ ps 명령어를 통해서 Docker 서비스가 Daemon이 정상 기동인지 프로세스를 확인합니다.
[root@docker-centos ~]# docker version Client: Docker Engine - Community Version: 23.0.4 API version: 1.42 Go version: go1.19.8 Git commit: f480fb1 Built: Fri Apr 14 10:36:38 2023 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 23.0.4 API version: 1.42 (minimum version 1.12) Go version: go1.19.8 Git commit: cbce331 Built: Fri Apr 14 10:34:14 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.20 GitCommit: 2806fc1057397dbaeefbea0e4e17bddfbd388f38 runc: Version: 1.1.5 GitCommit: v1.1.5-0-gf19387a docker-init: Version: 0.19.0 GitCommit: de40ad0
▶ 프로세스가 기동완료 되었으면 docker version 명령어를 통해서 Docker 엔진 설치가 완료된 것을 확인할 수 있습니다.
[root@docker-centos ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
▶ docker ps 명령어를 통해 아직 이미지 컨테이너가 배포되지 않았지만 목록 리스트를 확인할 수 있습니다.
[guru@docker-centos ~]$ docker ps 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/containers/json": dial unix /var/run/docker.sock: connect: permission denied
▶ Centos 또한 일반 계정(guru)에 대해서 접근권한을 부여하지 않았다면 docker 명령어를 수행할 수 없습니다. Ubuntu의 경우 sudo 명령어를 통해서 root 시스템을 통해서 서비스가 가능하지만, Centos의 경우 Group 멤버롤 별도 추가가 없는 경우 추가가 필요합니다.
[root@docker-centos ~]# cat /etc/group | grep -i docker docker:x:979:
▶ /etc/group 그룹 리스트(docker)를 확인합니다.
[root@docker-centos ~]# usermod -aG docker guru
▶usermod -aG docker guru 명령어를 통해서 docker 그룹에 guru 계정을 멤버로 추가합니다.
[root@docker-centos ~]# cat /etc/group | grep -i docker docker:x:979:guru
▶다시 /etc/group 그룹 리스트(docker)를 확인한 경우 멤버로 등록이 된 것을 확인할 수 있습니다.
[root@docker-centos ~]# su - guru 마지막 로그인: 금 4월 21 23:43:52 KST 2023 10.100.0.2에서 시작 일시 pts/0 [guru@docker-centos ~]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
▶ 일반계정(guru)에서도 docker ps 명령어가 실행되는 것을 확인할 수 있습니다.
PS. 포스팅의 내용은 제 기준으로 작성한 것이기 때문에 참고해서 보시면 감사하겠습니다.
포스팅 과정의 오류 및 오타 그리고 궁금한 점에 대해서는 댓글 남겨주세요.
2024.01.26 - [Programming and Database/Docker And Kubernetes] - Docker 컨테이너 Ubuntu에 설치하기
2024.01.25 - [Programming and Database/Docker And Kubernetes] - Docker Virtualbox Cent OS 설치하기
2024.01.24 - [Programming and Database/Docker And Kubernetes] - Docker Virtualbox Ubuntu OS 설치하기
728x90반응형'Programming and Database > Docker And Kubernetes' 카테고리의 다른 글
Docker 컨테이너 Ubuntu에 설치하기 (4) 2024.01.26 Docker Virtualbox Cent OS 설치하기 (2) 2024.01.25 Docker Virtualbox Ubuntu OS 설치하기 (10) 2024.01.24 Docker Virtualbox 설치 및 Centos용 VM 생성하기(2) (4) 2024.01.23 Docker Virtualbox 설치 및 Ubuntu용 VM 생성하기(1) (1) 2024.01.22