一張圖看懂docker命令
阿新 • • 發佈:2019-01-03
首先,上圖,該圖出自Docker —— 從入門到實踐的附錄部分,基本概括了docker的所有命令。
從圖中可以看到,對使用者來說,大部分命令都是針對倉庫(repository),映象(image),容器(container)操作使用的,其他還包括管理命令,比如網路(network),卷(volume),節點(node)等的管理。
通過shell檢視docker的幫助文件
$ docker --help
Usage: docker COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default
"/home/blinkdr/.docker")
-D, --debug Enable debug mode
--help Print usage
-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
"/home/blinkdr/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default
"/home/blinkdr/.docker/cert.pem" )
--tlskey string Path to TLS key file (default
"/home/blinkdr/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
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
Run 'docker COMMAND --help' for more information on a command.
可以看到,基本就是圖上所描述的,下面就分別來介紹一些常用命令,更詳細的用法,可以使用’–help’來檢視。
基本命令
倉庫相關操作
docker pull #從遠端倉庫拉取映象到本地
docker push #推送本地映象到遠端倉庫
docker search #在倉庫搜尋映象
docker login #登入到官方倉庫Docker Hub
docker logout #退出登入
映象相關操作
docker build #從Dockerfile構建映象
docker pull #同上
docker push #同上
docker history #顯示映象的歷史資訊
docker images #列出映象
docker rmi #刪除映象
docker tag #給映象打上tag標籤
docker run #建立容器並啟動容器
docker create #建立容器
docker commit #將修改後的容器生成映象
docker load #從壓縮包中載入映象
docker import #
docker save #將映象儲存到壓縮檔案
容器相關操作
docker attach #依附到一個正在執行的容器中
docker exec #進到正在執行的容器中執行命令
docker cp #在容器和本地系統間複製檔案
docker update #將一個容器內所有的程序從暫停狀態中恢復
docker ps #列出主機中的容器
docker port #查詢一個nat到私有網口的公共口
docker top #檢視一個容器中正在執行的程序資訊
docker logs #檢視日誌檔案
docker diff #檢查容器內檔案系統的修改
docker status #輸出容器的資源使用統計資訊
docker wait #阻塞直到容器終止
docker start #啟動已建立的容器
docker pause #暫停執行中的容器
docker unpause #使暫停的容器恢復執行
docker stop #停止容器執行
docker rename #容器改名
docker restart #容器重啟
docker kill #關閉執行中的容器
docker rm #刪除容器
docker export #匯出容器內容為tar包
docker run #同上
docker create #同上
docker commit #同上
其他基本命令
docker events #從服務端獲取實時的事件
docker info #檢視系統相關資訊
docker inspect #顯示Docker物件的具體配置資訊,包括容器,映象,網路等
docker version #輸出Docker的版本資訊
管理命令
docker container #容器管理
docker image #映象管理
docker network #網路管理
docker node #節點管理
docker plugin #外掛管理
docker secret #
docker service #服務管理
docker stack #
docker swarm #叢集管理
docker system #
docker volume #卷管理
管理命令不能直接直接使用,後面還要加上命令,比如映象管理
$ docker image --help
Usage: docker image COMMAND
Manage images
Options:
--help Print usage
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
可以看到跟基本命令對映象的操作類似,也包括build,pull,push等,比較常用的管理命令包括了
- image
- container
- network
- volume
具體的用法,可以使用–help來檢視