강좌
클라우드/리눅스에 관한 강좌입니다.
네트워크 분류

RockyLinux강좌09: RockyLinux에서 Docker로 Container 사용하기 2편

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

RockyLinux에서 기본적인 Docker 사용법 2편



Docker OS 자원을 사용하기 때문에 기본적으로 Root 사용자에서 명령어를 사용해야한다

Docker에서 실행되는 container들도 OS 자원을 사용하기 때문에 시스템의 하드웨어의 자원을 사용하게 된다. 따라서 Docker root사용자로 사용한다.

 

한가지 개념정리를 해야 것은

-
도커이미지 : 실행이 가능한 도커 이미지
-
컨테이너 : 실행되어 있는 상태의 도커이미지

     위의 개념을 정확히 정리하고 있어야 이해가 쉽다.

 

1.   도커의 기본적인 명령어 사용

 

-       컨테이너 확인
컨테이너란 실행중인 도커이미지를 의미한다.
“docker ps”
실행하면 현재 실행중인 컨테이너 목록을 나타낸다. 아래 보면 모두 “UP” 상태의 컨테이너들만 보인다는 것을 있다.

[root@sulinux01 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND        CREATED          STATUS          PORTS     NAMES
8c9d313b4d07   rockylinux/rockylinux   "/sbin/init"   22 minutes ago   Up 22 minutes             rockylinux
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"    37 minutes ago   Up 37 minutes             youthful_wozniak
[root@sulinux01 ~]#

 

-       이미 종료된 컨테이너까지 포함한 도커이미지를 확인한다.

“docker ps -a” 이미 종료된 컨테이너 목록까지 확인할 있다. 아래 보면 UP 상태의 컨테이너와 “Exited”상태의 컨테이너들을 있다.

[root@sulinux01 ~]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                   CREATED          STATUS                      PORTS     NAMES
8c9d313b4d07   rockylinux/rockylinux   "/sbin/init"              24 minutes ago   Up 24 minutes                         rockylinux
46878ce69be7   rockylinux/rockylinux   "/bin/bash"               32 minutes ago   Exited (0) 31 minutes ago             relaxed_lalande
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"               39 minutes ago   Up 39 minutes                         youthful_wozniak
247c8616e1a5   rockylinux/rockylinux   "/bin/bash"               42 minutes ago   Exited (0) 41 minutes ago             priceless_edison
c74f6bdd4189   hello-world             "/hello"                  6 hours ago      Exited (0) 6 hours ago                musing_pare
99bc4f13712e   nginx                   "/docker-entrypoint.…"   5 days ago       Exited (0) 5 days ago                 confident_bassi
18ab798827ba   hello-world             "/hello"                  5 days ago       Exited (0) 5 days ago                 pedantic_chatelet
[root@sulinux01 ~]#

 

-       종료된 컨테이너 시작하기

형식 : docker stasrt “컨테이너ID”

다음은 “docker ps -a” 실행하여 컨테이너들을 확인한 것이고, 이중 nginx라는 종료된 컨테이너를 “docker start 컨테이너ID” 다시 실행한 것이다.

[root@sulinux01 ~]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                   CREATED          STATUS                      PORTS     NAMES
8c9d313b4d07   rockylinux/rockylinux   "/sbin/init"              24 minutes ago   Up 24 minutes                         rockylinux
46878ce69be7   rockylinux/rockylinux   "/bin/bash"               32 minutes ago   Exited (0) 31 minutes ago             relaxed_lalande
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"               39 minutes ago   Up 39 minutes                         youthful_wozniak
247c8616e1a5   rockylinux/rockylinux   "/bin/bash"               42 minutes ago   Exited (0) 41 minutes ago             priceless_edison
c74f6bdd4189   hello-world             "/hello"                  6 hours ago      Exited (0) 6 hours ago                musing_pare
99bc4f13712e   nginx                   "/docker-entrypoint.…"   5 days ago       Exited (0) 5 days ago                 confident_bassi
18ab798827ba   hello-world             "/hello"                  5 days ago       Exited (0) 5 days ago                 pedantic_chatelet
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker start 99bc4f13712e
99bc4f13712e
[root@sulinux01 ~]#

 

 

-       컨테이너에 접속하기

 

[root@sulinux01 ~]# docker ps
CONTAINER ID   IMAGE                   COMMAND                   CREATED          STATUS          PORTS     NAMES
8c9d313b4d07   rockylinux/rockylinux   "/sbin/init"              37 minutes ago   Up 37 minutes             rockylinux
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"               52 minutes ago   Up 52 minutes             youthful_wozniak
99bc4f13712e   nginx                   "/docker-entrypoint.…"   5 days ago       Up 8 minutes    80/tcp    confident_bassi
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker attach 51cfd6629ce0
[root@51cfd6629ce0 /]#

위와 같이 종료된 컨테이너내에 들어 있고,

또한 해당 컨테이너 내에서 이전 하던작업들을 이어서 있다.

, 여러 개의 컨테이너들을 실행시켜두고 상황에 맞는 작업들을 그때 그때 있으며,

컨테이너를 종료했다가 다시 시작하여 이전에 하던 작업들(파일만들기, APM설치하기등.. 서버작업등) 추가로 있다.

당연한 얘기지만, 도커이미지를 삭제하기 전까지는 이전 상태 그대로 도커이미지가 존재하기 때문이다.

 

-       컨테이너 종료하기

다음과 같이 컨테이너를 종료할 있다.  하지만 컨테이너는 종료되더라도 다시 실행할 수가 있다.

[root@sulinux01 ~]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                   CREATED             STATUS                         PORTS     NAMES
b950f23f22ec   rockylinux/rockylinux   "/bin/bash"               39 seconds ago      Exited (127) 10 seconds ago              gracious_mendel
8c9d313b4d07   rockylinux/rockylinux   "/sbin/init"              48 minutes ago      Up 48 minutes                            rockylinux
46878ce69be7   rockylinux/rockylinux   "/bin/bash"               56 minutes ago      Exited (0) 55 minutes ago                relaxed_lalande
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"               About an hour ago   Exited (127) 9 minutes ago               youthful_wozniak
247c8616e1a5   rockylinux/rockylinux   "/bin/bash"               About an hour ago   Exited (0) About an hour ago             priceless_edison
c74f6bdd4189   hello-world             "/hello"                  6 hours ago         Exited (0) 6 hours ago                   musing_pare
99bc4f13712e   nginx                   "/docker-entrypoint.…"   5 days ago          Exited (0) 8 minutes ago                 confident_bassi
18ab798827ba   hello-world             "/hello"                  5 days ago          Exited (0) 5 days ago                    pedantic_chatelet
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker stop 18ab798827ba
18ab798827ba
[root@sulinux01 ~]#

 

-       컨테이너 삭제하기

앞에서 컨테이너를 종료하는 예를 보았다. 컨테이너는 종료되더라도 다시 실행할 있다고 하였기 때문에 필요가 없어진 컨테이너는 삭제하는 것이 좋다.

다음은 컨테이너를 삭제한 예이다.  

 

[root@sulinux01 ~]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                   CREATED              STATUS                         PORTS     NAMES
b950f23f22ec   rockylinux/rockylinux   "/bin/bash"               About a minute ago   Exited (127) 46 seconds ago              gracious_mendel
8c9d313b4d07   rockylinux/rockylinux   "/sbin/init"              49 minutes ago       Up 49 minutes                            rockylinux
46878ce69be7   rockylinux/rockylinux   "/bin/bash"               56 minutes ago       Exited (0) 56 minutes ago                relaxed_lalande
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"               About an hour ago    Exited (127) 9 minutes ago               youthful_wozniak
247c8616e1a5   rockylinux/rockylinux   "/bin/bash"               About an hour ago    Exited (0) About an hour ago             priceless_edison
c74f6bdd4189   hello-world             "/hello"                  6 hours ago          Exited (0) 6 hours ago                   musing_pare
99bc4f13712e   nginx                   "/docker-entrypoint.…"   5 days ago           Exited (0) 9 minutes ago                 confident_bassi
18ab798827ba   hello-world             "/hello"                  5 days ago           Exited (0) 5 days ago                    pedantic_chatelet
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker rm 18ab798827ba
18ab798827ba
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker rm 99bc4f13712e
99bc4f13712e
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker ps -a

CONTAINER ID   IMAGE                   COMMAND        CREATED             STATUS                            PORTS     NAMES
b950f23f22ec   rockylinux/rockylinux   "/bin/bash"    2 minutes ago       Exited (127) About a minute ago             gracious_mendel
8c9d313b4d07   rockylinux/rockylinux   "/sbin/init"   49 minutes ago      Up 49 minutes                               rockylinux
46878ce69be7   rockylinux/rockylinux   "/bin/bash"    57 minutes ago      Exited (0) 56 minutes ago                   relaxed_lalande
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"    About an hour ago   Exited (127) 10 minutes ago                 youthful_wozniak
247c8616e1a5   rockylinux/rockylinux   "/bin/bash"    About an hour ago   Exited (0) About an hour ago                priceless_edison
c74f6bdd4189   hello-world             "/hello"       6 hours ago         Exited (0) 6 hours ago                      musing_pare
[root@sulinux01 ~]#

위의 예에서 hello-world라는 컨테이너와 nginx라는 컨테이너를 삭제하고 확인한 것이다.

 

-       도커이미지 만들기

필요한 도커이미지를 얼마든지 생성할 있다. 이에 대한 자세한 설명은 다음기회에 하기로 하고 여기서는 간단하게 개념정도의 설명만 하겠다. 
Dockerfile
이라는 파일이름으로 도커파일을 만드는데 다음과 같은 형식이 있다.

 FROM “기본이미지

ADD “
이미지에 추가할 파일

RUN “
실행할 명령어

위의 형식에 갖추어진 dockerfile 있는 곳에서 docker build 실행한다.

형식 : docker build –tag “태그

 

2.   도커이미지 검색하기

도커허브(대표적인 hub.docker.com)에서 도커이미지를 검색한다.

[root@sulinux01 ~]# docker search rockylinux
NAME                                                DESCRIPTION                                      SAL   AUTOMATED
rockylinux                                          The official build of Rocky Linux.               1rockylinux/rockylinux                                                                                5
kasmweb/rockylinux-9-desktop                        Rocky Linux 9 desktop for Kasm Workspaces        0
kasmweb/rockylinux-8-desktop                        Rocky Linux 8 desktop for Kasm Workspaces        0
rockylinux/rockylinux-shim                          RockyLinux shim-review images                    0
rockylinux/rocky-toolbox                            Toolbox image for Rocky Linux - https://gith…   1
dokken/rockylinux-8                                 A docker container for use with Test Kitchen…   4
dokken/rockylinux-9                                                                                  2
spack/rockylinux9                                                                                    0
spack/rockylinux8                                                                                    0
litmusimage/rockylinux                                                                               0
oowy/rockylinux                                     RockyLinux Docker image with systemd init sy…   0
arm64v8/rockylinux                                  The official build of Rocky Linux.               1
amd64/rockylinux                                    The official build of Rocky Linux.               0
robertdebock/rockylinux                             Container to test Ansible roles in, includin…   0
106061/rockylinux_cicd                              For CI/CD RockyLinux                             0
romcheck/rockylinux                                                                                  0
arpaesimc/rockylinux                                                                                 0
tdsfdw/rockylinux8-postgresql                       Rocky Linux 7 images with PostgreSQL officia…   0
mhaluska/rockylinux-php                             Container based on Rocky Linux with Apache2 …   0
gammabytehosting/rockylinux                         Rocky Linux minimal image.                       1
bordercloud/rockylinux-apache-php-mariadb-rdfunit                                                    0
bordercloud/rockylinux-virtuoso7                                                                     0
tallu/rockylinux8-openjdk11                         OpenJDK 11 image using rockylinux8               0
pats22/rockylinux8-rcli                                                                              0
[root@sulinux01 ~]#

 

3.   도커이미지 가져오기

원하는 도커이미지를 가져온다.

[root@sulinux01 ~]# docker pull rockylinux/rockylinux
Using default tag: latest
latest: Pulling from rockylinux/rockylinux
71cc2ddb2ecf: Pull complete
Digest: sha256:fc370d748f4cd1e6ac3d1b6460fb82201897fa15a16f43e947940df5aca1a56e
Status: Downloaded newer image for rockylinux/rockylinux:latest
docker.io/rockylinux/rockylinux:latest
[root@sulinux01 ~]#

 

4.   도커이미지 확인

가져온 도커이미지들을 확인한다.  현재 서버에 존재하는 도커이미지들을 확인한다.

[root@sulinux01 ~]# docker images

REPOSITORY              TAG       IMAGE ID       CREATED         SIZEnginx                   latest    6efc10a0510f   2 weeks ago     142MB
httpd                   latest    4b7fc736cb48   3 weeks ago     145MB
ubuntu                  latest    08d22c0ceb15   8 weeks ago     77.8MB
rockylinux/rockylinux   latest    523ffac7fb2e   9 months ago    196MB
hello-world             latest    feb5d9fea6a5   19 months ago   13.3kB
centos                  latest    5d0da3dc9764   19 months ago   231MB
[root@sulinux01 ~]#

방금 받았던 rockylinux 라는 이름의 도커이미지를 있다.
용량을 보면 196M 정도 밖에 안된다. 가상화된 운영체제이지만 용량이 이렇게 작은 이유는 도커이미지에는 커널이 포함되어 있지 않고, 서비스를 하기 위한 파일들만 존재하기 때문이다. 만약 rockylinux 실제로 설치해서 사용한다면 이보다는 수십배 용량이 필요할 것이다. 도커를 사용하는 이유중 하나이다.

 

 

5.   도커이미지로 컨테이너생성하고 컨테이너 접속하기

사용형식 : docker run 옵션 도커이미지 실행파일

         이경우 알아 두어야 것은, “실행파일 실행했던

 

옵션은 다음과 같은 것들이 있다.


 -i (interactive) :
사용자가 입출력할 있다.
 -t :
가상터미널을 에뮬레이션한다.
-d :
실행된 컨테이너를 일반프로세스가 아닌 데몬프로세스로 실행하여 프로세스가 종료되어도 컨테이너를 계속 유지한다.

 

[root@sulinux01 ~]# docker images
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
nginx                   latest    6efc10a0510f   2 weeks ago     142MB
httpd                   latest    4b7fc736cb48   3 weeks ago     145MB
ubuntu                  latest    08d22c0ceb15   8 weeks ago     77.8MB
rockylinux/rockylinux   latest    523ffac7fb2e   9 months ago    196MB
hello-world             latest    feb5d9fea6a5   19 months ago   13.3kB
centos                  latest    5d0da3dc9764   19 months ago   231MB
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker run docker.io/rockylinux/rockylinux
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                   CREATED         STATUS                     PORTS     NAMES
eb7ba96c6d3f   rockylinux/rockylinux   "/bin/bash"               8 seconds ago   Exited (0) 7 seconds ago             eloquent_jemison
c74f6bdd4189   hello-world             "/hello"                  5 hours ago     Exited (0) 5 hours ago               musing_pare
99bc4f13712e   nginx                   "/docker-entrypoint.…"   5 days ago      Exited (0) 5 days ago                confident_bassi
18ab798827ba   hello-world             "/hello"                  5 days ago      Exited (0) 5 days ago                pedantic_chatelet
[root@sulinux01 ~]#

“docker ps -a” 도커이미지로 실행된 컨테이너들을 확인한 것이다. 첫번째 컨테이너로서 “rockylinux/rockylinux”라는 컨테이너가 8초전에 실행되었다는 것을 있다. 그리고 “STATUS” 보면 “Exited (0) 7 seconds”라고 되어 있는데, 이것의 의미는 도커는 도커이미지를 실행한 결과를 반환만하고 종료되었다는 의미이다.

그렇다면 종료되지 않고 계속 유지하기 위해서는 어떻게 하면 될까?

 

6.   컨테이너가 실행된 상태 유지하기

메인실행파일이 종료되면 해당 컨테이너도 함께 종료된다. 이경우 컨테이너가 종료되지 않고 계속 유지되도록 하기 위해서는 지속적으로 실행될 파일을 지정해 주면 된다.

[root@sulinux01 ~]# cat /etc/redhat-release
Rocky Linux release 9.1 (Blue Onyx)
[root@sulinux01 ~]#
[root@sulinux01 ~]# ls -l
합계 23276
-rw-------. 1 root root     1452  4
26 10:58 anaconda-ks.cfg
-rw-r--r--  1 root root        0  5
  2 17:30 imsi
-rw-r--r--  1 root root     3887  5
  1 11:51 imsi.txt
drwxr-xr-x  3 root root       37  5
  3 10:01 imsidir
-rw-------  1 root root  1870031  5
  3 09:59 messages
drwx-----T  2 root root        6  5
  2 17:20 testdir
-rwS------  1 root root        0  5
  2 17:23 testfile
drwxr-xr-x  5 1006 1006     4096  9
25  2022 wordpress
-rw-r--r--  1 root root 21948964  9
25  2022 wordpress-6.0.2-ko_KR.tar.gz
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker run -i -t docker.io/rockylinux/rockylinux /bin/bash
[root@ec329ab72106 /]#
[root@ec329ab72106 /]# ls -l
total 0
lrwxrwxrwx   1 root root   7 Oct 11  2021 bin -> usr/bin
drwxr-xr-x   5 root root 360 May  3 07:13 dev
drwxr-xr-x   1 root root  66 May  3 07:13 etc
drwxr-xr-x   2 root root   6 Oct 11  2021 home
lrwxrwxrwx   1 root root   7 Oct 11  2021 lib -> usr/lib
lrwxrwxrwx   1 root root   9 Oct 11  2021 lib64 -> usr/lib64
drwx------   2 root root   6 Jul  7  2022 lost+found
drwxr-xr-x   2 root root   6 Oct 11  2021 media
drwxr-xr-x   2 root root   6 Oct 11  2021 mnt
drwxr-xr-x   2 root root   6 Oct 11  2021 opt
dr-xr-xr-x 240 root root   0 May  3 07:13 proc
dr-xr-x---   2 root root 162 Jul  7  2022 root
drwxr-xr-x  11 root root 163 Jul  7  2022 run
lrwxrwxrwx   1 root root   8 Oct 11  2021 sbin -> usr/sbin
drwxr-xr-x   2 root root   6 Oct 11  2021 srv
dr-xr-xr-x  13 root root   0 May  3 07:13 sys
drwxrwxrwt   2 root root  58 Jul  7  2022 tmp
drwxr-xr-x  12 root root 144 Jul  7  2022 usr
drwxr-xr-x  19 root root 249 Jul  7  2022 var
[root@ec329ab72106 /]#
[root@ec329ab72106 /]# uname -a
Linux ec329ab72106 5.14.0-162.23.1.el9_1.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 11 19:09:37 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
[root@ec329ab72106 /]#
[root@ec329ab72106 /]# cat /etc/redhat-release
Rocky Linux release 8.6 (Green Obsidian)
[root@ec329ab72106 /]#
[root@ec329ab72106 /]# exit
exit
[root@sulinux01 ~]#
[root@sulinux01 ~]# ls -l
합계 23276
-rw-------. 1 root root     1452  4
26 10:58 anaconda-ks.cfg
-rw-r--r--  1 root root        0  5
  2 17:30 imsi
-rw-r--r--  1 root root     3887  5
  1 11:51 imsi.txt
drwxr-xr-x  3 root root       37  5
  3 10:01 imsidir
-rw-------  1 root root  1870031  5
  3 09:59 messages
drwx-----T  2 root root        6  5
  2 17:20 testdir
-rwS------  1 root root        0  5
  2 17:23 testfile
drwxr-xr-x  5 1006 1006     4096  9
25  2022 wordpress
-rw-r--r--  1 root root 21948964  9
25  2022 wordpress-6.0.2-ko_KR.tar.gz
[root@sulinux01 ~]#

위에서 exit 대신 “CTRL+D” 해도 동일하게 exit 된다.  이경우에는 메일실행파일인 쉘종료와 함께 컨테이너도 함께 종료된다.

 

만약 메인파일이 종료가 되더라도 컨테이너를 계속 유지하고 싶다면 “CTRL+P+Q”를하고 호스트OS 빠져 나오면 된다.

[root@sulinux01 ~]# docker run -i -t docker.io/rockylinux/rockylinux /bin/bash
[root@51cfd6629ce0 /]#
[root@51cfd6629ce0 /]# [root@sulinux01 ~]#      [
여기서 CTRL+P+Q 눌러서 컨테이너에서 호스트OS 빠져나옴]
[root@sulinux01 ~]#
[root@sulinux01 ~]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                   CREATED          STATUS                     PORTS     NAMES
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"               37 seconds ago   Up 36 seconds                        youthful_wozniak
247c8616e1a5   rockylinux/rockylinux   "/bin/bash"               3 minutes ago    Exited (0) 3 minutes ago             priceless_edison
c74f6bdd4189   hello-world             "/hello"                  5 hours ago      Exited (0) 5 hours ago               musing_pare
99bc4f13712e   nginx                   "/docker-entrypoint.…"   5 days ago       Exited (0) 5 days ago                confident_bassi
18ab798827ba   hello-world             "/hello"                  5 days ago       Exited (0) 5 days ago                pedantic_chatelet
[root@sulinux01 ~]#

 

7.   컨테이너 내에서 작업하기

다음 예는 컨테이너 안에서 testfile 생성하고 해당 컨테이너를 빠져나와서(CTRL+D, 또는 exit) 호스트OS에서 파일을 확인한 것이다. 그렇지만 testfile 보이지 않는다. 파일은 컨테이너안에서 생성하였기 때문에 보이지 않는다.

[root@sulinux01 ~]# docker run -i -t docker.io/rockylinux/rockylinux /bin/bash
[root@46878ce69be7 /]#
[root@46878ce69be7 /]# cd
[root@46878ce69be7 ~]#
[root@46878ce69be7 ~]# pwd
/root
[root@46878ce69be7 ~]#
[root@46878ce69be7 ~]# ls -l
total 12
-rw------- 1 root root 2359 Jul  7  2022 anaconda-ks.cfg
-rw-r--r-- 1 root root  737 Jul  7  2022 anaconda-post.log
-rw------- 1 root root 1899 Jul  7  2022 original-ks.cfg
[root@46878ce69be7 ~]#
[root@46878ce69be7 ~]# touch testfile
[root@46878ce69be7 ~]#
[root@46878ce69be7 ~]# ls -l
total 12
-rw------- 1 root root 2359 Jul  7  2022 anaconda-ks.cfg
-rw-r--r-- 1 root root  737 Jul  7  2022 anaconda-post.log
-rw------- 1 root root 1899 Jul  7  2022 original-ks.cfg
-rw-r--r-- 1 root root    0 May  3 07:31 testfile
[root@46878ce69be7 ~]#
[root@46878ce69be7 ~]# exit
exit
[root@sulinux01 ~]#
[root@sulinux01 ~]# ls -l
합계 23276
-rw-------. 1 root root     1452  4
26 10:58 anaconda-ks.cfg
-rw-r--r--  1 root root        0  5
  2 17:30 imsi
-rw-r--r--  1 root root     3887  5
  1 11:51 imsi.txt
drwxr-xr-x  3 root root       37  5
  3 10:01 imsidir
-rw-------  1 root root  1870031  5
  3 09:59 messages
drwxr-xr-x  5 1006 1006     4096  9
25  2022 wordpress
-rw-r--r--  1 root root 21948964  9
25  2022 wordpress-6.0.2-ko_KR.tar.gz
[root@sulinux01 ~]#

 

 

 

8.   컨테이너 내에서 작업하기

[root@sulinux01 ~]# docker run -d --name rockylinux docker.io/rockylinux/rockylinux /sbin/init
8c9d313b4d07e5a11e988909cc4045a38a4aa48a702644df9f9c9630cd0dc430
[root@sulinux01 ~]#


위에서는 /sbin/init 컨테이너를 백그라운드로 실행시킨 것이다.
그리고 다음은 확인한 것이다.


[root@sulinux01 ~]# docker ps -a
CONTAINER ID   IMAGE                   COMMAND                   CREATED          STATUS                      PORTS     NAMES
8c9d313b4d07   rockylinux/rockylinux   "/sbin/init"              15 seconds ago   Up 14 seconds                         rockylinux
46878ce69be7   rockylinux/rockylinux   "/bin/bash"               8 minutes ago    Exited (0) 7 minutes ago              relaxed_lalande
51cfd6629ce0   rockylinux/rockylinux   "/bin/bash"               15 minutes ago   Up 15 minutes                         youthful_wozniak
247c8616e1a5   rockylinux/rockylinux   "/bin/bash"               17 minutes ago   Exited (0) 17 minutes ago             priceless_edison
c74f6bdd4189   hello-world             "/hello"                  5 hours ago      Exited (0) 5 hours ago                musing_pare
99bc4f13712e   nginx                   "/docker-entrypoint.…"   5 days ago       Exited (0) 5 days ago                 confident_bassi
18ab798827ba   hello-world             "/hello"                  5 days ago       Exited (0) 5 days ago                 pedantic_chatelet
[root@sulinux01 ~]#
[root@sulinux01 ~]#

다음은 실행한 컨테이너에 docker exec 실행하여 /bin/bash프로세스를 생성한 것이다.


[root@sulinux01 ~]# docker exec -i -t rockylinux /bin/bash
[root@8c9d313b4d07 /]#

그런다음 컨테이너 내에서  httpd php 그리고 MariaDB 설치한 것이다.

[root@8c9d313b4d07 /]# dnf -y install httpd
Rocky Linux 8 - AppStream                                              11 MB/s |  11 MB     00:00
Rocky Linux 8 - BaseOS                                                8.2 MB/s | 6.1 MB     00:00
Rocky Linux 8 - Extras                                                 20 kB/s |  14 kB     00:00
Dependencies resolved.
..............

 

[root@8c9d313b4d07 /]# dnf -y install php
Last metadata expiration check: 0:00:17 ago on Wed May  3 07:41:50 2023.
Dependencies resolved.
===========================================================================
 Package               Arch        Version                                       Repository      Size
===========================================================================
Installing:
..............

 

[root@8c9d313b4d07 /]# dnf -y install mariadb-server
Last metadata expiration check: 0:00:29 ago on Wed May  3 07:41:50 2023.
Dependencies resolved.
===========================================================================
 Package                      Arch     Version                                      Repository   Size
===========================================================================
Installing:
 mariadb-server               x86_64   3:10.3.35-1.module+el8.6.0+1005+cdf19c22     appstream    16 M

Complete!
[root@8c9d313b4d07 /]#

 

그런다음 httpd php 그리고 mariaDB 설치되었는가를 확인한 것이다.

 

[root@8c9d313b4d07 ~]# rpm -qa httpd
httpd-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64
[root@8c9d313b4d07 ~]#
[root@8c9d313b4d07 ~]# rpm -qa php
php-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64
[root@8c9d313b4d07 ~]#
[root@8c9d313b4d07 ~]# rpm -qa mariadb-server
mariadb-server-10.3.35-1.module+el8.6.0+1005+cdf19c22.x86_64
[root@8c9d313b4d07 ~]#

 

 

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,037 명
  • 현재 강좌수 :  35,806 개
  • 현재 접속자 :  93 명