頁內(nèi)導(dǎo)航
操作image
查看當(dāng)前image列表
docker image ls [OPTIONS] [REPOSITORY[:TAG]]
List images
Aliases:
ls, images, list
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
--no-trunc Don''t truncate output
-q, --quiet Only show numeric IDs
文檔中指出有docker image ls
,docker image list
和docker images
三條命令均可以完成查看鏡像操作。
獲取鏡像
docker image pull [OPTIONS] NAME[:TAG|@DIGEST] [flags]
Options:
-a, --all-tags Download all tagged images in the repository
--disable-content-trust Skip image verification (default true)
--platform string Set platform if server is multi-platform capable
Params:
NAME 鏡像名稱氓仲。鏡像可以在Docker Store上查找其名稱。一般是
user/repo:tag的格式
鏡像可以通過上述命令先獲取到本地。Docker的查詢在Docker Store進(jìn)行。
例如
搜索 niweigede 就會(huì)獲得以下結(jié)果
可以看出蝎抽,這個(gè)鏡像的描述使用了
ubuntu
,java-8
,ssh
以及tsinghua
的apt 源洪囤。
獲取鏡像還可以使用docker pull
命令
刪除鏡像
docker image rm [OPTIONS] IMAGE [IMAGE...]
Remove one or more images
Aliases:
rm, rmi, remove
Options:
-f, --force Force removal of the image
--no-prune Do not delete untagged parents
刪除鏡像時(shí),IMAGE參數(shù)可以指定鏡像名稱或者鏡像ID路媚。
如果被刪除的鏡像A,在本地有基于A制作的鏡像B樊销,則直接刪除A會(huì)報(bào)'conflict: unable to delete 5a662682895c (cannot be forced) - image has dependent child images'錯(cuò)誤整慎。此時(shí)需要先解除關(guān)聯(lián),也就是先刪除B才能繼續(xù)刪除A
運(yùn)行鏡像
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
run
命令下的OPTIONS
比較多围苫,這里不完全羅列裤园,需要的請自行查詢。
運(yùn)行鏡像并進(jìn)入控制臺(tái)
docker run -i -t niweigede/ujava:1.1
上述命令表示基于鏡像niweigede/ujava:1.1
打開一個(gè)新的container剂府。其中-i
表示保持一個(gè)標(biāo)準(zhǔn)輸入STDIN
,-t
表示分配一個(gè)虛擬控制臺(tái)TTY
用于與container進(jìn)行交互
建立與宿主機(jī)器網(wǎng)絡(luò)的端口映射
docker run -it -p 8070:8080 niweigede/ujava:1.1
使用命令-p
端口映射拧揽,詳細(xì)的使用方式如下
format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
Both hostPort and containerPort can be specified as a range of ports.
When specifying ranges for both, the number of container ports in the range
must match the number of host ports in the range. (e.g., `-p 1234-1236:1234-1236/tcp`)
自定義container名稱
docker run -it --name CUSTOMER_NAME niweigede/ujava:1.1
使用命令--name
給即將運(yùn)行的container分配一個(gè)自定的名稱"CUSTOMER_NAME"
添加數(shù)據(jù)卷volume掛載
docker run -it -v /home/host:/home/container niweigede/ujava:1.1
使用命令-v
進(jìn)行數(shù)據(jù)卷掛載,詳細(xì)的使用方式如下
Create a bind mount with: [host-dir:]container-dir[:rw|ro].
If 'host-dir' is missing, then docker creates a new volume.
If neither 'rw' or 'ro' is specified then the volume is mounted
in read-write mode.
發(fā)布鏡像
要發(fā)布鏡像,必須要有docker的賬號(hào)淤袜。
docker push [OPTIONS] NAME[:TAG]
Push an image or a repository to a registry
Options:
--disable-content-trust Skip image signing (default true)
系列文章
<Docker 1> Docker入門知識(shí)和安裝方式
<Docker 2> Docker的常用命令簡介
<Docker 3> Docker image的操作 當(dāng)前