이번장에서는 Docker 설치 후 많이 사용되는 커맨드들에 대해 살펴보자.
Docker Version 및 설정 정보 확인
# docker version : docker cli 가 docker engine 과 통신하는지 확인용도로 사용
$ docker version
# docker info : docker engine 에 대한 config 정보를 얻음
$ docker info
|
Docker 명령어 조회
docker 에 대한 명령어 조회는 docker 라고 치면 된다.
docker 의 명령 방식은 예전부터 사용하던 docker <command> (options) 방식과
docker run
최근 버전에서 추가된 docker <Management Commands> <command> (options) 방식이 있다.
docker container run
두번째 방식의 조회는 마찬가지로 docker <Management Commands> 를 화면에 치면
후위 <command> 에 대한 정보를 얻을 수 있다.
# docker 의 모든 커맨드 조회
$ docker
Usage: docker COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands: (신규 커맨드 타입)
config Manage Docker configs
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands: (기존 커맨드 차입)
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
# docker <Management Command> <Command> (Options) 형식의 커맨드 조회
$ docker container
Usage: docker container COMMAND
Manage containers
Commands:
attach Attach local standard input, output, and error streams to a running container
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
exec Run a command in a running container
export Export a container's filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes
|
Container
Container 쪽에서 자주 사용되는 기본 명령어는 다음과 같다.
Container 실행
컨테이너를 시작하는 경우 docker run 명령을 사용할 수 있다.
-d 옵션을 붙여 명령어가 backgroud 로 실행할 수 있다.
# run container foreground
$ docker run <imageName>
# run container background
$ docker run -d <imageName>
|
Container 에 명령실행
실행중인 컨테이너에 특정 커맨드를 실행시키기 위해서는 docker exec 명령을 사용한다.
$ docker exec <containerName> <commands>
|
Container 리스트 조회
현재 실행중인 컨테이너 리스트를 보고자 하는 경우 docker ps 명령을 사용할 수 있다.
-a 옵션을 주면 사용이 중지된 컨테이너 리스트도 나타난다.
# list containers
$ docker ps
# list containers ( include exited )
$ docker ps -a
|
Container 정지
실행중인 컨테이너를 정지하고자 하는 경우 docker stop 명령을 사용할 수 있다.
$ docker stop <Container Name>
|
Container 삭제
stop 된 상태의 컨테이너를 영구히 삭제하고자 하는 경우 docker rm 명령을 사용할 수 있다.
$ docker rm <Container Name>
|
Image
Image 쪽에서 자주 사용되는 기본 명령어는 다음과 같다.
Image 다운로드
docker run 과 달리 단순히 이미지만 로컬 레포지토리로 다운로드 받고자 하는 경우에는
docker pull 명령을 실행한다.
$ docker pull <imageName>
|
Image 조회
이미 다운로드 되어 있는 이미지를 조회하는 경우 docker images 명령을 실행한다
$ docker images
|
Image 삭제
다운로드 되어 있는 이미지를 삭제하는 경우 docker rmi 명령을 실행한다
$ docker rmi <imageName>
|