IT Log

docker 본문

Open Source/Docker

docker

newly0513 2019. 12. 11. 20:40
728x90
반응형
  • docker run - docker실행
  • docker exec - container 내부 접속
  • docker images - docker image 리스트
  • docker ps - docker container 리스트

docker run

사용방법

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

 

 

OPTIONS

  • -d : Run container in background and print container ID
  • -e : Set environment variables
  • -h : Container host name
  • -i : Keep STDIN open even if not attached
  • --link : Add link to another container
  • --name : Assign a name to the container
  • -p : port
  • --rm : Automatically remove the container when it exits
  • -t : allocate a pseudo-TTY
  • -v : Bind mount a volume

※ 옵션이 너무 많아 써본 것만 나열하고 다른 OPTION들은 아래 사이트에서 참고

 

Examples

docker run -it --rm --name example -e environment -p 외부port:내부port --link container:container -v local경로:container경로

 

자세한 설명은 https://docs.docker.com/engine/reference/commandline/run/


docker exec

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

OPTINS

  • -d : run command in the background
  • -e : Set environment variables
  • -i : Keep STDIN open even if not attached
  • --privileged : Give extended privileges to the command
  • -t : Allocate a pseudo-TTY
  • -u : Username or UID
  • -w : Working directory inside the container

Examples

# container 내부 접속
docker exec -it <container name> or <container ID> bash

 

자세한 설명은 https://docs.docker.com/engine/reference/commandline/exec/


docker images

docker images [OPTIONS] [REPOSITORY[:TAG]]

OPTINS

  • -a : Show all images
  • --digests : Show digests
  • -f : Filter output based on conditions provided
  • --format : Pretty-print images using a Go template
  • --no-trunc : Don't truncate output
  • -q : Only show numeric IDs

Examples

docker images
docker images java:8
docker images --no-trunc
docker images --digests
docker images --filter "label=com.example.version"

 

Tip

# image list 전체 삭제
docker rmi $(docker images)

 

자세한 설명은 https://docs.docker.com/engine/reference/commandline/images/


docker ps

docker ps [OPTIONS]

OPTINS

  • -a : Show all containers
  • -f : Filter output based on conditions provided
  • --format : Pretty-print images using a Go template
  • -n : Show n last created containers using a Go template
  • -l : Show the latest created container
  • --no-trunc : Don't truncate output
  • -q : Only show numeric IDs
  • -s : Display total file sizes

Examples

docker ps -a
$ docker ps --filter status=paused

 

Tip

# container list 전체 삭제
docker rm $(docker ps -a -q)

 

자세한 설명은 https://docs.docker.com/engine/reference/commandline/images/


 

728x90
반응형

'Open Source > Docker' 카테고리의 다른 글

Docker Compose Install  (0) 2020.07.16
Docker Install  (0) 2020.07.16
Docker Compose  (0) 2019.12.12
Comments