상세 컨텐츠

본문 제목

10.컨테이너 관리 - 컨테이너 실행, 시작, 종료, 리스트

엔지니어일기/RHCSA준비

by jaws99 2022. 11. 2. 23:07

본문

반응형

컨테이너 실행하기

# -d 옵션으로 컨테이너를 백그라운드로 실행
$ podman run -d nginx
2de34264984ef6c5c9decdb4a0847801bd17e27e93fd7c614ffaadd2b5b5d16b

# ps 명령어로 실행된 컨테이너 확인.
$ podman ps
CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS            PORTS       NAMES
2de34264984e  docker.io/library/nginx:latest  nginx -g daemon o...  2 seconds ago  Up 2 seconds ago              romantic_jang

# -it + /bin/bash로 컨테이너 내부로 들어갈 수 있다.
# (Ctrl + P + Q)로 컨테이너에서 나올 수 있습니다.
$ podman run -it nginx /bin/bash
root@e779d4becc8e:/# ls
bin   dev		   docker-entrypoint.sh  home  lib64  mnt  proc  run   srv  tmp  var
boot  docker-entrypoint.d  etc			 lib   media  opt  root  sbin  sys  usr

# p 옵션으로 포트 설정
$ podman run -d -p 9999:80 nginx
c98ece2c04092202312e5a6a43b9400fb9c299722b94dd2d206bde5ab1c678d8

$ podman port -a
c98ece2c0409	80/tcp -> 0.0.0.0:9999

# curl로 포트포워딩 확인.
$ curl localhost:9999
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

 

컨테이너 Stop & Start

$ podman ps
CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS             PORTS                 NAMES
0dd17bedaef2  docker.io/library/nginx:latest  nginx -g daemon o...  46 seconds ago  Up 47 seconds ago  0.0.0.0:9999->80/tcp  romantic_jang

$ podman stop 0dd17bedaef2
0dd17bedaef2

$ podman ps
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

# Running이 아닌 컨테이너도 모두 표시
$ podman ps -a
CONTAINER ID  IMAGE                           COMMAND               CREATED             STATUS                           PORTS                 NAMES
0dd17bedaef2  docker.io/library/nginx:latest  nginx -g daemon o...  55 seconds ago      Exited (0) 4 seconds ago         0.0.0.0:9999->80/tcp  romantic_jang

$ podman start 0dd17bedaef2
0dd17bedaef2

$ podman ps
CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS           PORTS                 NAMES
0dd17bedaef2  docker.io/library/nginx:latest  nginx -g daemon o...  2 minutes ago  Up 1 second ago  0.0.0.0:9999->80/tcp  romantic_jang

 

컨테이너 삭제 

$ podman ps -a
CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS                      PORTS                 NAMES
d5b480d2eabb  docker.io/library/nginx:latest  -p 9999:80            4 minutes ago  Exited (127) 4 minutes ago                        gallant_mahavira
0dd17bedaef2  docker.io/library/nginx:latest  nginx -g daemon o...  4 minutes ago  Up 2 minutes ago            0.0.0.0:9999->80/tcp  romantic_jang

# Running이 아닌 컨테이너들을 전부 삭제
$ podman container prune
WARNING! This will remove all non running containers.
Are you sure you want to continue? [y/N] y
d5b480d2eabb25316b2a1e9668aa89414f758929ceb3839cda0493c92bd96354

 

컨테이너에서 command 실행하기

# container에서 command 실행
$ podman exec 2de34264984e ls -al
total 12
dr-xr-xr-x.   1 root root   39 Nov  2 13:49 .
dr-xr-xr-x.   1 root root   39 Nov  2 13:49 ..
drwxr-xr-x.   2 root root 4096 Oct 24 00:00 bin
drwxr-xr-x.   2 root root    6 Sep  3 12:10 boot
.....

 

반응형

관련글 더보기