容器是一種清理級、可移植、自包含的軟體打包技術,使應用程式可以在幾乎任何地方以相同的方式運行。 ...
目錄
本地鏡像管理
docker images
: 列出本地鏡像;docker rmi
:刪除本地鏡像;docker tag
:標記本地鏡像;docker build
:使用DockerFile創建鏡像;docker history
:查看指定鏡像的創建歷史;docker save
:將指定鏡像保存成tar歸檔文件;docker load
:導入使用docker save
命令導出的鏡像;docker import
:從歸檔文件中創建鏡像;docker commit
:從容器修改中創建新的鏡像;
列出本地鏡像
語法如下:
docker images [OPTIONS] [REPOSITORY[:TAG]]
Options:
-a, --all Show all images (default hides intermediate images(預設隱藏中間鏡像層))
--digests Show digests(顯示摘要信息)
-f, --filter filter Filter output based on conditions provided(顯示滿足條件的鏡像)
--format string Pretty-print images using a Go template
--help Print usage
--no-trunc Don't truncate output(顯示完整的鏡像信息)
-q, --quiet Only show numeric IDs
刪除本地鏡像
語法如下:
docker rmi [OPTIONS] IMAGE [IMAGE...]
Options:
-f, --force Force removal of the image(強制刪除鏡像)
--no-prune Do not delete untagged parents(不移除該鏡像的過程鏡像,預設移除)
例如:
# 刪除所有鏡像
docker rmi $(docker images -q)
# 批量刪除無用鏡像
docker rmi $(docker images -f dangling=true)
標記本地鏡像
語法如下:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
使用DockerFile創建鏡像
語法如下:
docker build [OPTIONS] PATH | URL | -
Options:
--build-arg list Set build-time variables (default [])
--cache-from stringSlice Images to consider as cache sources
--cgroup-parent string Optional parent cgroup for the container
--compress Compress the build context using gzip
--cpu-period int Limit the CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit the CPU CFS (Completely Fair Scheduler) quota
-c, --cpu-shares int CPU shares (relative weight)
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
--disable-content-trust Skip image verification (default true)
-f, --file string Name of the Dockerfile (Default is 'PATH/Dockerfile')
--force-rm Always remove intermediate containers
--help Print usage
--isolation string Container isolation technology
--label list Set metadata for an image (default [])
-m, --memory string Memory limit
--memory-swap string Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--network string Set the networking mode for the RUN instructions during build (default "default")
--no-cache Do not use cache when building the image
--pull Always attempt to pull a newer version of the image
-q, --quiet Suppress the build output and print image ID on success
--rm Remove intermediate containers after a successful build (default true)
--security-opt stringSlice Security options
--shm-size string Size of /dev/shm, default value is 64MB
-t, --tag list Name and optionally a tag in the 'name:tag' format (default [])
--ulimit ulimit Ulimit options (default [])
查看指定鏡像的創建歷史
語法如下:
docker history [OPTIONS] IMAGE
Options:
-H, --human Print sizes and dates in human readable format (default true)
--no-trunc Don't truncate output
-q, --quiet Only show numeric IDs
鏡像保存
語法如下:
docker save [OPTIONS] IMAGE [IMAGE...]
Options:
-o, --output string Write to a file, instead of STDOUT
鏡像導入
語法如下:
docker load [OPTIONS]
Options:
-i, --input string Read from tar archive file, instead of STDIN
-q, --quiet Suppress the load output
從歸檔文件中創建鏡像
語法如下:
docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Options:
-c, --change list Apply Dockerfile instruction to the created image (default [])
-m, --message string Set commit message for imported image
從容器修改中創建新鏡像
語法如下:
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Options:
-a, --author string Author (e.g., "John Hannibal Smith <[email protected]>")
-c, --change list Apply Dockerfile instruction to the created image (default [])
-m, --message string Commit message
-p, --pause Pause container during commit (default true)