작성일자: 2024.08.26
Ver 0.1.1
1. Docker 명령어 구조
- Docker의 모든 명령은 'docker'로 시작하며 어떤 대상에게 명령어를 실행할 것인지로 구분하면 보기 쉽다.
docker {대상} {커맨드} {옵션} {인자}
대표적인 커맨드 대상 : docker container / image / volume / network
- Docker에서 사용할 수 있는 커맨드 리스트는 아래와 같이 확인할 수 있음
1) 'docker' 입력
2) 'docker [command 대상] -- help' 입력
3) 위와 같은 방법으로 커맨드 수준을 높이고 뒤에 --help 입력
(base) MacBookAir ~ % docker
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Common Commands:
run Create and run a new container from an image
exec Execute a command in a running container
ps List containers
build Build an image from a Dockerfile
pull Download an image from a registry
push Upload an image to a registry
images List images
login Log in to a registry
logout Log out from a registry
search Search Docker Hub for images
version Show the Docker version information
info Display system-wide information
Management Commands:
builder Manage builds
buildx* Docker Buildx (Docker Inc., v0.16.1-desktop.1)
compose* Docker Compose (Docker Inc., v2.29.1-desktop.1)
container Manage containers
context Manage contexts
debug* Get a shell into any image or container (Docker Inc., 0.0.34)
desktop* Docker Desktop commands (Alpha) (Docker Inc., v0.0.14)
dev* Docker Dev Environments (Docker Inc., v0.1.2)
extension* Manages Docker extensions (Docker Inc., v0.2.25)
feedback* Provide feedback, right in your terminal! (Docker Inc., v1.0.5)
image Manage images
init* Creates Docker-related starter files for your project (Docker Inc., v1.3.0)
manifest Manage Docker image manifests and manifest lists
network Manage networks
plugin Manage plugins
sbom* View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
scout* Docker Scout (Docker Inc., v1.11.0)
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Swarm Commands:
swarm Manage Swarm
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
events Get real time events from the server
export Export a container's filesystem as a tar archive
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
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
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
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
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
wait Block until one or more containers stop, then print their exit codes
Global Options:
--config string Location of client config files (default "/Users/limjongjun/.docker")
-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")
-D, --debug Enable debug mode
-H, --host list Daemon socket 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 "/Users/limjongjun/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/Users/limjongjun/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/Users/limjongjun/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Run 'docker COMMAND --help' for more information on a command.
For more help on how to use Docker, head to https://docs.docker.com/go/guides/
2. docker container 주요 커맨드
'docker container' 이후에 작성하는 주요 커맨드는 아래와 같다.
커맨드 | 설명 | 주요옵선 |
start | 컨테이너 실행 | -i |
stop | 컨테이너 정지 | |
create | 컨테이너 생성 | --name, -e, -p, -v |
run | 이미지를 내려받고 컨테이너를 생성 및 실행 | --name, -e, -p, -v, -d, -i, -t |
rm | 컨테이너 삭제 | -f, -v |
exec | 컨테이너에서 프로그램 실행 | -i, -t |
ls | 컨테이너 목록 출력 | -a |
cp | 컨테이너와 호스트가 파일 복사 | |
commit | 컨테이너를 이미지로 변환 |
3. docker image 주요 커맨드
'docker image' 이후에 작성하는 주요 커맨드는 아래와 같음
커맨드 | 설명 | 주요 옵션 |
pull | 이미지를 내려받음 | |
rm | 이미지 삭제 | |
ls | 가지고 있는 이미지 목록을 출력 | |
build | 이미지 생성 |
4. 주요 옵션
옵션 | 설명 |
--name | 컨테이너 이름 |
-p | 포트 번호 지정 |
-v | 볼륨 설정 |
-e | 환경 변수 설정 |
-d | 백그라운드 실행 |
-i | 컨테이너에 터미널 연결 |
-t | 특수 키를 사용가능하게 설정 |