鏡像是什麼node
鏡像從哪裏來python
鏡像和容器的關係nginx
存儲驅動docker
鏡像管理命令json
什麼是鏡像:vim
簡單說,Docker鏡像是一個不包含Linux內核並且又精簡的Linux操做系統(內核是共享宿主機的)centos
鏡像從哪裏來?app
Docker Hub 是由Docker公司負責維護的公共註冊中心,包含大量的容器鏡像,Docker工具默認從這個鏡像來下載鏡像 https://hub.docker.com/explore,工具
這個是國外的鏡像源,因此下載會很慢,有時候還會被牆,因此咱們換成國內的鏡像性能
vim /etc/docker/daemon.json
添加內容:
{
"registry-mirrors":["https://registry.docker-cn.com"]
}
systemctl restart docker 重啓docker
docker images 查看咱們下載的鏡像有哪些
docker pull nginx:1.12 安裝nginx鏡像(不指定版本號的話,默認版本latest)
鏡像和容器的關係:
鏡像不是一個單一的文件,而是有多層構成,咱們能夠經過docker history <ID/NAME>查看鏡像中各層內容及大小,每層對應着Dockerfile中的一條指令,Docker鏡像默認存儲在/var/lib/docker/<storge-driver>中
容器實際上是在鏡像的最上層加了一層讀寫層,在運行容器裏作的任何文件改動,都會寫到這個讀寫層,若是容器刪除了,嘴上面的讀寫層也就刪除了。改動也就丟失了。
Docker 使用存儲驅動管理鏡像每層內容以及可讀寫層的容器層
docker history haproxy:1.7 命令咱們能夠看到鏡像內部執行的history命令
存儲驅動:(Docker 在管理驅動的時候都是經過這個驅動去管理容器的)
aufs Ubuntu
devicemapper centos
overlay 只支持ext4,xfs文件系統
overlay2(性能比overlay好),只支持ext4,xfs文件系統
Docker管理指令:
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
Docker image 指令:
[root@node02 ~]# docker image --help Usage: docker image COMMAND Manage images Options: 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.
[root@node02 ~]# docker tag nginx:1.7.9 nginx:v1.7.9 給nginx:1.7.9 打一個tag v1.7.9 [root@node02 ~]# docker images | grep nginx nginx latest ae513a47849c 4 months ago 109MB nginx 1.7.9 84581e99d807 3 years ago 91.6MB nginx v1.7.9 84581e99d807 3 years ago 91.6MB
[root@node02 ~]# docker image save nginx:1.7.9 >nginx.1.7.9.tar
[root@node02 ~]# docker load < nginx.1.7.9.tar
Loaded image: nginx:1.7.9
指令 | 描述 |
ls | 列出鏡像 |
build | 構建鏡像來自Dockerfile |
history | 查看鏡像歷史 |
inspect | 顯示一個或多個鏡像詳細信息 |
pull | 從鏡像倉庫拉取鏡像 |
push | 推送一個鏡像到鏡像倉庫 |
rm | 移除一個或多個鏡像 |
prune | 移除未使用的鏡像。沒有被標記或被任何容器引用的。 |
tag | 建立一個引用源鏡像標記目標鏡像 |
export | 導出容器文件系統到tar歸檔文件 |
import | 導入容器文件系統tar歸檔文件建立鏡像 |
save | 保存一個或多個鏡像到一個tar歸檔文件 |
load | 加載鏡像來自tar歸檔或標準輸入 |