RockyLinux강좌09: RockyLinux에서 Docker로 Container 사용하기 1편
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 6,976 조회
- 0 추천
- 목록
본문
도커를 사용해야 하는 이유를 간단히 작성해 본다.
가정 : 아파치서버를 별도로 돌려야 한다고 가정해보자.
방법1 : 다른 서버에 별도로 리눅스설치 -> 아파치설치 -> 실행
방법2 : VirtualBox나 VMWare (또는 KVM등) 등을 이용해서 현재 사용하고 있는 서버에서 VM(가상머신)을 만들고 VM에 OS설치하고 Apache를 올린다.
방법3 : 현재 시스템에 Docker저장소를 만들고 아파치 Docker Image를 다운로드 한 다음 다운로드한 아파치 Image를 실행(Container가 된다.)한다.
위의 방법 1번보다는 2번이 훨씬 간편하고, 2번보다는 3번이 훨씬 간편하다.
이것이 Docker를 사용하는 이유이다.
- 도커저장소 : hub.docker.com, 도커저장소를 도커허브라고도 한다. 여기에 도커이미지들이 많이 있으며, 원하는 이미지(image)를 다운로드해서 사용한다.
- 도커저장소에서 다운로드한 이미지를 실제로 작동시킨것들을 컨테이너(container)라고 한다.
1. 도커저장소를 추가한다.
[root@sulinux01 ~]# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo |
2. 도커를 설치한다.
[root@sulinux01 ~]# dnf -y install docker-ce docker-ce-cli containerd.io Docker CE Stable - x86_64 58 kB/s | 23 kB 00:00 Rocky Linux 9 - BaseOS 6.0 kB/s | 4.1 kB 00:00 Rocky Linux 9 - AppStream 6.3 kB/s | 4.5 kB 00:00 Rocky Linux 9 - Extras 4.1 kB/s | 2.9 kB 00:00 종속성이 해결되었습니다. ================================================================================ 꾸러미 구조 버전 레포지터리 크기 ================================================================================ 설치 중: containerd.io x86_64 1.6.20-3.1.el9 docker-ce-stable 33 M 교체 runc.x86_64 4:1.1.4-1.el9_1 docker-ce x86_64 3:23.0.5-1.el9 docker-ce-stable 23 M docker-ce-cli x86_64 1:23.0.5-1.el9 docker-ce-stable 7.1 M 향상 중: buildah x86_64 1:1.27.3-1.el9_1 appstream 7.9 M 종속 꾸러미 설치 중: docker-ce-rootless-extras x86_64 23.0.5-1.el9 docker-ce-stable 3.8 M 취약한 종속 꾸러미 설치 중: docker-buildx-plugin x86_64 0.10.4-1.el9 docker-ce-stable 12 M docker-compose-plugin x86_64 2.17.3-1.el9 docker-ce-stable 11 M 연결 요약 ================================================================================ 설치 6 꾸러미 향상 1 꾸러미 총계 내려받기 크기: 98 M 꾸러미 내려받기 중: (1/7): docker-buildx-plugin-0.10.4-1.el9.x86_64 13 MB/s | 12 MB 00:00 (2/7): docker-ce-23.0.5-1.el9.x86_64.rpm 18 MB/s | 23 MB 00:01 (3/7): docker-ce-cli-23.0.5-1.el9.x86_64.rpm 13 MB/s | 7.1 MB 00:00 (4/7): docker-ce-rootless-extras-23.0.5-1.el9.x 9.2 MB/s | 3.8 MB 00:00 (5/7): buildah-1.27.3-1.el9_1.x86_64.rpm 21 MB/s | 7.9 MB 00:00 (6/7): docker-compose-plugin-2.17.3-1.el9.x86_6 13 MB/s | 11 MB 00:00 (7/7): containerd.io-1.6.20-3.1.el9.x86_64.rpm 12 MB/s | 33 MB 00:02 -------------------------------------------------------------------------------- 합계 30 MB/s | 98 MB 00:03 Docker CE Stable - x86_64 14 kB/s | 1.6 kB 00:00 GPG키 0x621E9F35 가져오는 중: 사용자 ID : "Docker Release (CE rpm) <docker@docker.com>" 지문: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35 출처 : https://download.docker.com/linux/centos/gpg 키 가져오기에 성공했습니다 연결 확인 실행 중 연결 확인에 성공했습니다. 연결 시험 실행 중 연결 시험에 성공했습니다. 연결 실행 중 준비 중 : 1/1 설치 중 : docker-compose-plugin-2.17.3-1.el9.x86_64 1/9 스크립트릿 실행 중: docker-compose-plugin-2.17.3-1.el9.x86_64 1/9 설치 중 : docker-buildx-plugin-0.10.4-1.el9.x86_64 2/9 스크립트릿 실행 중: docker-buildx-plugin-0.10.4-1.el9.x86_64 2/9 설치 중 : docker-ce-cli-1:23.0.5-1.el9.x86_64 3/9 스크립트릿 실행 중: docker-ce-cli-1:23.0.5-1.el9.x86_64 3/9 설치 중 : containerd.io-1.6.20-3.1.el9.x86_64 4/9 스크립트릿 실행 중: containerd.io-1.6.20-3.1.el9.x86_64 4/9 설치 중 : docker-ce-rootless-extras-23.0.5-1.el9.x86_64 5/9 스크립트릿 실행 중: docker-ce-rootless-extras-23.0.5-1.el9.x86_64 5/9 설치 중 : docker-ce-3:23.0.5-1.el9.x86_64 6/9 스크립트릿 실행 중: docker-ce-3:23.0.5-1.el9.x86_64 6/9 향상 중 : buildah-1:1.27.3-1.el9_1.x86_64 7/9 정리 : buildah-1:1.27.2-2.el9_1.x86_64 8/9 사용 중지 : runc-4:1.1.4-1.el9_1.x86_64 9/9 스크립트릿 실행 중: runc-4:1.1.4-1.el9_1.x86_64 9/9 확인 중 : containerd.io-1.6.20-3.1.el9.x86_64 1/9 확인 중 : runc-4:1.1.4-1.el9_1.x86_64 2/9 확인 중 : docker-buildx-plugin-0.10.4-1.el9.x86_64 3/9 확인 중 : docker-ce-3:23.0.5-1.el9.x86_64 4/9 확인 중 : docker-ce-cli-1:23.0.5-1.el9.x86_64 5/9 확인 중 : docker-ce-rootless-extras-23.0.5-1.el9.x86_64 6/9 확인 중 : docker-compose-plugin-2.17.3-1.el9.x86_64 7/9 확인 중 : buildah-1:1.27.3-1.el9_1.x86_64 8/9 확인 중 : buildah-1:1.27.2-2.el9_1.x86_64 9/9 향상되었습니다: buildah-1:1.27.3-1.el9_1.x86_64 설치되었습니다: containerd.io-1.6.20-3.1.el9.x86_64 docker-buildx-plugin-0.10.4-1.el9.x86_64 docker-ce-3:23.0.5-1.el9.x86_64 docker-ce-cli-1:23.0.5-1.el9.x86_64 docker-ce-rootless-extras-23.0.5-1.el9.x86_64 docker-compose-plugin-2.17.3-1.el9.x86_64 완료되었습니다! [root@sulinux01 ~]# |
3. 도커서비스를 가동한다.
[root@sulinux01 ~]# systemctl restart docker [root@sulinux01 ~]# [root@sulinux01 ~]# systemctl enable docker Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service. [root@sulinux01 ~]# [root@sulinux01 ~]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disa> Active: active (running) since Fri 2023-04-28 10:58:21 KST; 18s ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 3045 (dockerd) Tasks: 7 Memory: 30.3M CPU: 234ms CGroup: /system.slice/docker.service └─3045 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 4월 28 10:58:20 sulinux01 systemd[1]: Starting Docker Application Container Engine... 4월 28 10:58:21 sulinux01 dockerd[3045]: time="2023-04-28T10:58:21.029829095+09:00" leve> 4월 28 10:58:21 sulinux01 dockerd[3045]: time="2023-04-28T10:58:21.061610872+09:00" leve> 4월 28 10:58:21 sulinux01 dockerd[3045]: time="2023-04-28T10:58:21.527060238+09:00" leve> 4월 28 10:58:21 sulinux01 dockerd[3045]: time="2023-04-28T10:58:21.551999775+09:00" leve> 4월 28 10:58:21 sulinux01 dockerd[3045]: time="2023-04-28T10:58:21.552079556+09:00" leve> 4월 28 10:58:21 sulinux01 systemd[1]: Started Docker Application Container Engine. 4월 28 10:58:21 sulinux01 dockerd[3045]: time="2023-04-28T10:58:21.586485692+09:00" leve> [root@sulinux01 ~]# |
4. 도커작동 테스트하기
hello-world라는 컨테이너는 현재 시스템의 도커에는 없으며, 도커허브에서 다운로드한 후에 실행해준다.
도커의 정상적인 작동유무를 테스트하기 위한 용도로 시스템관리자들이 간편하게 사용한다.
[root@sulinux01 ~]# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e 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: For more examples and ideas, visit: https://docs.docker.com/get-started/ [root@sulinux01 ~]# |
5. 도커이미지 다운해서 Container 생성해보기
현재 우리가 사용하고 있는 시스템은 RockyLinux이다.
이 시스템에서 CentOS를 사용하고자 할때에,
도커허브에서 CentOS 도커이미지를 다운로드해서 이 이미지를 실행해보자.
먼저 도커허브에서 centos 이미지를 확인한다.
[root@sulinux01 ~]# docker pull centos Using default tag: latest latest: Pulling from library/centos a1d0c7532777: Pull complete Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177 Status: Downloaded newer image for centos:latest docker.io/library/centos:latest [root@sulinux01 ~]# [root@sulinux01 ~]# docker run -it centos bash [root@d546f105119f /]# [root@d546f105119f /]# cat /etc/redhat-release CentOS Linux release 8.4.2105 [root@d546f105119f /]# [root@d546f105119f /]# ls -l total 0 lrwxrwxrwx 1 root root 7 Nov 3 2020 bin -> usr/bin drwxr-xr-x 5 root root 360 Apr 28 02:38 dev drwxr-xr-x 1 root root 66 Apr 28 02:38 etc drwxr-xr-x 2 root root 6 Nov 3 2020 home lrwxrwxrwx 1 root root 7 Nov 3 2020 lib -> usr/lib lrwxrwxrwx 1 root root 9 Nov 3 2020 lib64 -> usr/lib64 drwx------ 2 root root 6 Sep 15 2021 lost+found drwxr-xr-x 2 root root 6 Nov 3 2020 media drwxr-xr-x 2 root root 6 Nov 3 2020 mnt drwxr-xr-x 2 root root 6 Nov 3 2020 opt dr-xr-xr-x 193 root root 0 Apr 28 02:38 proc dr-xr-x--- 2 root root 162 Sep 15 2021 root drwxr-xr-x 11 root root 163 Sep 15 2021 run lrwxrwxrwx 1 root root 8 Nov 3 2020 sbin -> usr/sbin drwxr-xr-x 2 root root 6 Nov 3 2020 srv dr-xr-xr-x 13 root root 0 Apr 28 02:38 sys drwxrwxrwt 7 root root 171 Sep 15 2021 tmp drwxr-xr-x 12 root root 144 Sep 15 2021 usr drwxr-xr-x 20 root root 262 Sep 15 2021 var [root@d546f105119f /]# [root@d546f105119f /]# [root@d546f105119f /]# exit exit [root@sulinux01 ~]# |
위의 예는 CentOS 도커이미지를 다운로드 해서,
다운로드한 도커이미지를 실행한 것이다.
실행하면 CentOS 환경으로 변한다.
간단히 사용해보고 exit로 빠져 나온것이다.
다음은 간단한 자주사용하는 Container를 확인하고 삭제하는 도커 명령어들이다.
먼저, 현재 실행된 도커 컨테이너들을 확인하기 위해 "docker images"를 실행한 화면이다.
이 화면에서 보면 좀 전에 실행했던. centos 컨테이너가 보인다.
[root@sulinux01 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 6efc10a0510f 2 weeks ago 142MB httpd latest 4b7fc736cb48 2 weeks ago 145MB ubuntu latest 08d22c0ceb15 7 weeks ago 77.8MB hello-world latest feb5d9fea6a5 19 months ago 13.3kB centos latest 5d0da3dc9764 19 months ago 231MB [root@sulinux01 ~]# |
다음은 현재 설치된 컨테이너들의 상세정보를 확인하기 위해 "docker container ls -a"를 실행한 것이다.
[root@sulinux01 ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d546f105119f centos "bash" 4 minutes ago Exited (0) 4 minutes ago eager_shockley 99bc4f13712e nginx "/docker-entrypoint.…" 25 minutes ago Exited (0) 24 minutes ago confident_bassi 18ab798827ba hello-world "/hello" 42 minutes ago Exited (0) 42 minutes ago pedantic_chatelet [root@sulinux01 ~]# |
그리고 다음은 특정 컨테이너를 삭제하기 위해 "docker rm 컨테이너ID"를 실행한다.
여기서는 바로 앞에서 설치했던 centos 컨테이너를 삭제한 것이다.
그런 다음 다시 한번 더 컨테이너들의 정보를 확인해 본 것이다.
centos 컨테이너가 삭제되고 없다는 것을 알 수 있다.
[root@sulinux01 ~]# docker rm d546f105119f d546f105119f [root@sulinux01 ~]# [root@sulinux01 ~]# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 99bc4f13712e nginx "/docker-entrypoint.…" 25 minutes ago Exited (0) 25 minutes ago confident_bassi 18ab798827ba hello-world "/hello" 43 minutes ago Exited (0) 43 minutes ago pedantic_chatelet [root@sulinux01 ~]# |
관련자료
-
이전
-
다음