반응형

 

ChatGPT의 도움을 받아 다시 정리합니다

 

 

1. pull

        도커 허브나 레포지토리에서 도커 이미지를 다운 받습니다.

        docker  pull  도커_이미지_이름

        # docker  pull  nginx

Using default tag: latest
latest: Pulling from library/nginx
ae79f2514705: Pull complete
e6c178db6dc5: Pull complete
f6d5f9744165: Pull complete
Digest: sha256:6c017a056f1b6c87a39f60af1ba7d29904b13c53d1a02b25d26f7f460c90fc2d
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

 

 

2. run 

        도커 이미지를 기반으로 컨테이너를 생성하고 실행

        로컬에 없을경우 다운로드해서 컨테이너를 생성하고 실행

 

        -it :  터미널 /쉘 사용 : 컨테이너 안에서 로그를 지켜볼 수 있음 

                외부에서 docker events 를 통해서도 지켜볼 수 있음

        -d : 백그라운드

 

        -itd : 백그라운드로 실행, 나중에 터미널로 들어가겠음

        -it :  바로 컨테이너 안으로 들어가서 프롬프트를 보겠음

 

        --hostname : 도커 컨테이너 호스트 네임 설정, 호스트 네임이 없으면 컨테이너 ID로 호스트명이 지정됨

                           

        docker  run  -itd  도커_이미지

        #  docker  run  -itd  nodejs-container 

root@nodejs-container:/#

 

 

3. start

        중지된 컨테이너를 시작합니다.

        docker start  컨테이너_ID 또는 컨테이너_이름

        #  docker  start  nodejs-container 

nodejs-container

 

 

4. attach

        컨테이너 안 터미널로 들어갑니다

        attach 명령어는 터미널이 백그라운드에서 실행 중인 경우, 예기치 않은 결과가 발생할 수 있습니다

        ">" 라고 나오는 경우가 있습니다.

        그래서 exec 를 권장합니다.

        docker  attach  컨테이너_ID 또는 컨테이너_이름

        #  docker  attach  nodejs-container 

 

 

5. exec

        실행중인 컨테이너에서 명령어를 실행합니다.

        컨테이너 안 터미널로 들어갈때는 bash

        -itd 를 하면 컨테이너 내부 쉘로 접근이 안된다. 

        docker  exec  -it  컨테이너_이름  bash

        #  docker  exec  -it  nodejs-container  bash

root@nodejs-container:/#

 

 

        #  docker  exec   nodejs-container   echo  "Hello World!"

Hello World!

 

 

        컨테이너 안 프로그램 실행 확인 #1

        service 프로그램명 status

        컨테이너#  service vsftpd starus

root@ftp-container:/# service vsftpd status
 * FTP server is running

 

 

        컨테이너 안 프로그램 실행 확인 #2

        systemctl  status  프로그램명 

        컨테이너#  system  status  vsftpd 

root@ftp-container:/# systemctl status vsftpd
 * FTP server is running

 

        오류발생 ?
        Operation not permitted
        systemctl 명령어를 실행할 때, 사용자 권한이 충분하지 않아서 발생할 수 있는 오류입니다.
        systemctl 명령어는 root 권한이 필요합니다. 

        docker exec 명령어를 실행할 때 -u 옵션을 사용하여 root 권한으로 컨테이너 안에 들어갈 수 있습니다.

        docker  exec  -u  root  -it  컨테이너_이름  bash

        # docker  exec  -u  root  -it  ftp-container  bash

docker exec -u root -it ftp-container bash

 

 

        오류발생 ?
        Failed to get D-Bus connection: Operation not permitted
        알파인 리눅스에서 FTP 서버의 상태를 확인하기 위해서는 rc-service 명령어를 사용해야 합니다.

        rc-service  프로그램_이름  status

        컨테이너_이름#  rc-service  vsftpd  status

rc-service vsftpd status

 

 

        오류발생 ?

        bash: rc-service: command not found

        rc-service 명령어가 없다는 메시지가 나타나면 다른 방법을 시도해 볼 수 있습니다.

        docker exec  컨테이너_이름  ps  aux  |  grep  프로그램_이름

        #  docker exec ftp-container ps aux | grep vsftpd

localhost:~# docker exec ftp-container ps aux | grep vsftpd
root         1  0.0  0.0  18036  2864 pts/0    Ss+  Apr20   0:00 /bin/bash /usr/sbin/run-vsftpd.sh
root        10  0.0  0.0  24048  2596 pts/0    S+   Apr20   0:00 vsftpd /etc/vsftpd/vsftpd.conf

 

반응형