본문 바로가기

Devops/Docker

[Docker] Docker 명령어 정리 #1

도커 컨테이너 리스트 보기

root@worker2:~# docker container ps --help

Usage:  docker container ls [OPTIONS]

List containers

Aliases:
  ls, ps, list

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display container IDs
  -s, --size            Display total file sizes

 

root@worker2:~# docker container ls -a (docker ps -a)
CONTAINER ID   IMAGE                                            COMMAND                  CREATED       STATUS                    PORTS                                                 NAMES

8a91bbb7c9c1   k8s.gcr.io/pause:3.6                             "/pause"                 8 days ago    Exited (0) 6 days ago                                                           k8s_POD_kube-proxy-t4fgr_kube-system_2e1cf20c-e04f-4548-b18e-2cd0ce5c3138_1
dcd8aae1bc47   store/oracle/database-enterprise:12.2.0.1-slim   "/bin/sh -c '/bin/ba…"   10 days ago   Up 39 minutes (healthy)   0.0.0.0:1521->1521/tcp, :::1521->1521/tcp, 5500/tcp   local_db

 

도커 컨테이터 Restart. Start

docker restart [Container ID, Names]

docker start [Container ID, Names]

 

root@worker1:~# docker restart app
app
root@worker1:~# docker ps
CONTAINER ID   IMAGE               COMMAND               CREATED       STATUS         PORTS                                       NAMES
71aa8dc3af78   kindlove/test:0.2   "java -jar app.war"   10 days ago   Up 5 seconds   0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   app

 

도커 컨테이터 Stop

docker container stop 3149209c1c12 (Container ID)
docker container stop blueocean (Names)

docker stop 3149209c1c12 (Container 단어 생략 가능)
docker stop blueocean

 

도커 컨테이터 삭제

root@worker2:~# docker rm --help
Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
Options:
  -f, --force     Force the removal of a running container (uses SIGKILL)
  -l, --link      Remove the specified link
  -v, --volumes   Remove anonymous volumes associated with the container

 

docker rm local_db (컨테이터 이름 또는 ID)

 

도커 이미지 조회

docker images

root@worker2:~# docker images
REPOSITORY                         TAG             IMAGE ID       CREATED        SIZE
k8s.gcr.io/kube-proxy              v1.23.1         b46c42588d51   13 days ago    112MB
calico/node                        v3.21.2         f1bca4d4ced2   3 weeks ago    214MB
calico/pod2daemon-flexvol          v3.21.2         7778dd57e506   3 weeks ago    21.3MB
calico/cni                         v3.21.2         4c5c32530391   3 weeks ago    239MB
k8s.gcr.io/pause                   3.6             6270bb605e12   4 months ago   683kB
store/oracle/database-enterprise   12.2.0.1-slim   27c9559d36ec   4 years ago    2.08GB

 

도커 이미지 삭제

docker image rm [Image ID]

docker rmi [Image ID]