DevOps/Docker

[도커]명령어 모음

박한결 2021. 5. 31. 11:44

도커 사용하기

 

Usage:  docker [OPTIONS] COMMAND

 

도커는 서버를 코드 형태로 정의해서 이미지를 만들고, 이미지를 사용해서 컨테이너를 실행한다. 따라서 일관성 유지와 버전 관리가 편하다.

 

이미지 출처: https://docs.docker.com/engine/reference/commandline/cli/

 


(1) 도커 이미지

 

🐋 도커 이미지

  • 여러개의 레이어로 구성됨
  • 각 레이어는 Read Only
  • 이미지로 컨테이너를 실행해서 파일을 생성하고 삭제할 때 새로운 레이어를 만들어 내용 저장 → 컨테이너와 함께 삭제되는 런타임 데이터임 → 영구적으로 저장하려면 볼륨(Bind Mount, Volume)을 사용해야 함
  • 디스크에 저장된 상태
  • 프로그램을 실행하는데 필요한 설정과 소프트웨어 종속성(프로그래밍 언어 런타임 및 기타 소프트웨어 라이브러리의 특정 버전 등)을 가지고 있다.

 

🐋 관련 명령어


(2) 도커 컨테이너 실행

 

🐋 도커 컨테이너

  • 이미지가 메모리에 올라가 있는 상태
  • 이미지의 인스턴스로 프로그램을 실행한다.
  • 하나의 컨테이너 당 하나의 애플리케이션 실행이 권장됨

 

🐋 관련 명령어

🐋 docker run vs docker start

  • docker run: 이미지의 새 컨테이너를 만들고 컨테이너를 실행한다. 동일한 이미지에 대해 N 개의 복제본을 생성 할 수있다.
  • docker start: 이전에 중지된 컨테이너를 시작한다. 즉 기존에 존재하는 컨테이너를 시작할 때 사용하는 명령어다(start 이전에 create 명령어를 사용해야 한다).

 

🐋 docker run option

  • -i, --interactive : Keep STDIN open even if not attached(연결되어 있지 않아도 표준 입력 유지)
  • -t, --tty : Allocate a pseudo-TTY(가상 터미널 지정)
  • -d, --detach : Run container in background and print container ID(컨테이너 실행 시 분리 모드로 실행)
  • --name string : Assign a name to the container(컨테이너 이름 지정)

(3) 도커 컨테이너 관리

 

🐋 관련 명령어

 

docker top 명령어는 옵션을 지정하지 않은 경우 리눅스의 ps -ef 와 동일한 역할을 한다.  docker diff 명령어는 컨테이너가 생성 된 이후 컨테이너의 파일 시스템에서 변경된 파일 및 디렉토리를 나열한다. 세 가지 유형의 변경이 추적된다. Symbol A는 파일 또는 디렉토리가 추가된 경우, D는 파일 또는 디렉토리가 삭제된 경우, 마지막으로 C는 파일 또는 디렉토리가 변경된 경우를 의미한다.

 

- 출처: https://docs.docker.com/engine/reference/commandline/diff/


 

 

* 참고

🐋 docker options

  1. -config string   -   Location of client config files (default "/root/.docker")
  2. -c, --context string  -   Name of the context to use to connect to the daemon(overrides DOCKER_HOST env var and default context set with "docker context use")
  3. -D, --debug       -       Enable debug mode
  4. -H, --host list    -      Daemon socket(s) to connect to
  5. -l, --log-level string   Set the logging level("debug"|"info"|"warn"|"error"|"fatal") (default "info")
  6. --tls       -         Use TLS; implied by --tlsverify
  7. --tlscacert string  -  Trust certs signed only by this CA (default "/root/.docker/ca.pem")
  8. --tlscert string   -  Path to TLS certificate file (default "/root/.docker/cert.pem")
  9. --tlskey string   -   Path to TLS key file (default "/root/.docker/key.pem")
  10. --tlsverify      -    Use TLS and verify the remote
  11. -v, --version      -      Print version information and quit

 

🐋 docker commands

  1. attach   -   Attach local standard input, output, and error streams to a running container
  2. build   -    Build an image from a Dockerfile
  3. commit    -  Create a new image from a container's changes
  4. cp    -      Copy files/folders between a container and the local filesystem
  5. create    -  Create a new container
  6.  diff   -     Inspect changes to files or directories on a container's filesystem
  7. events  -    Get real time events from the server
  8. exec   -     Run a command in a running container
  9. export   -   Export a container's filesystem as a tar archive
  10. history  -   Show the history of an image
  11. images  -    List images
  12. import   -   Import the contents from a tarball to create a filesystem image
  13. info   -     Display system-wide information
  14. inspect   -  Return low-level information on Docker objects
  15. kill   -     Kill one or more running containers
  16. load   -     Load an image from a tar archive or STDIN
  17. login  -     Log in to a Docker registry
  18. logout  -    Log out from a Docker registry
  19. logs     -   Fetch the logs of a container
  20. pause  -     Pause all processes within one or more containers
  21. port    -    List port mappings or a specific mapping for the container
  22. ps    -      List containers
  23. pull    -    Pull an image or a repository from a registry
  24. push   -     Push an image or a repository to a registry
  25. rename   -   Rename a container
  26. restart  -   Restart one or more containers
  27. rm     -    Remove one or more containers
  28. rmi    -     Remove one or more images
  29.  run    -     Run a command in a new container
  30. save   -     Save one or more images to a tar archive (streamed to STDOUT by default)
  31. search   -   Search the Docker Hub for images
  32. start   -    Start one or more stopped containers
  33. stats   -    Display a live stream of container(s) resource usage statistics
  34. stop   -     Stop one or more running containers
  35. tag    -     Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  36. top    -     Display the running processes of a container
  37. unpause   -  Unpause all processes within one or more containers
  38. update   -   Update configuration of one or more containers
  39. version  -   Show the Docker version information
  40. wait   -     Block until one or more containers stop, then print their exit codes

🐋 Management Commands:

  1. app*    -    Docker App (Docker Inc., v0.9.1-beta3)
  2. builder  -   Manage builds
  3. buildx*  -   Build with BuildKit (Docker Inc., v0.5.1-docker)
  4. config   -   Manage Docker configs
  5. container -  Manage containers
  6. context  -   Manage contexts
  7. image   -    Manage images
  8. manifest  -  Manage Docker image manifests and manifest lists
  9. network  -   Manage networks
  10. node  -      Manage Swarm nodes
  11. plugin  -    Manage plugins
  12. scan* -      Docker Scan (Docker Inc.)
  13. secret   -   Manage Docker secrets
  14. service  -   Manage services
  15. stack   -    Manage Docker stacks
  16. swarm    -   Manage Swarm
  17. system   -   Manage Docker
  18. trust  -     Manage trust on Docker images
  19. volume   -   Manage volumes

 

- 출처: https://docs.docker.com/go/guides/