Docker基本概念
Docker镜像
什么是镜像
在Docker中容器是基于镜像启动的
镜像是启动容器的核心
镜像采用分层设计
使用快照的COW技术,确保底层数据不丢失
前端盘是容器后端盘是镜像(多个镜像)
查看版本
[root@docker01 ~]# docker version
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built:
OS/Arch: linux/amd64
Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built:
OS/Arch: linux/amd64
查看镜像
[root@docker01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED
搜索镜像
[root@docker01 ~]# docker search busybox
下载镜像
[root@docker01 ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
75a0e65efd51: Extracting 32.77 kB/733.2 kB
[ 2905.178019] XFS (dm-1): Mounting V5 Filesystem
75a0e65efd51: Extracting 733.2 kB/733.2 kB
75a0e65efd51: Pull complete
Digest: sha256:d21b79794850b4b15d8d332b451d95351d14c951542942a816eea69c9e04b240
Status: Downloaded newer image for busybox:latest
下载、上传镜像
docker查看命令帮助的方法
[root@docker01 ~]# docker help pull
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Pull an image or a repository from a registry
Options:
-a, --all-tags Download all tagged images in the repository
--disable-content-trust Skip image verification (default true)
--help Print usage
导入、导出镜像
[root@docker01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 22c2dd5ee85d 7 days ago 1.163 MB
[root@docker01 ~]# docker save busybox:latest > busybox.tar
[ 4713.500105] XFS (dm-1): Mounting V5 Filesystem
[ 4713.596887] XFS (dm-1): Ending clean mount
[ 4713.764337] XFS (dm-1): Unmounting Filesystem
[root@docker01 ~]# ls
anaconda-ks.cfg busybox.tar ifcfg-eth0 RPM-GPG-KEY-CentOS-7
docker load < busybox.tar
[root@docker01 ~]# lftp 192.168.6.254
lftp 192.168.6.254:~> cd public
cd ok, cwd=/public
lftp 192.168.6.254:/public> ls
-rw-r--r-- 1 0 0 19917380 Jul 24 02:12 docker-engine-1.12.1-1.el7.centos.x86_64.rpm
-rw-r--r-- 1 0 0 28860 Jul 24 02:12 docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm
-rw-r--r-- 1 0 0 258246973 Jul 24 02:12 docker_images.zip
drwxr-xr-x 2 0 0 4096 Jul 24 02:13 repodata
lftp 192.168.6.254:/public> get docker_images.zip
258246973 bytes transferred
lftp 192.168.6.254:/public> ls
-rw-r--r-- 1 0 0 19917380 Jul 24 02:12 docker-engine-1.12.1-1.el7.centos.x86_64.rpm
-rw-r--r-- 1 0 0 28860 Jul 24 02:12 docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm
-rw-r--r-- 1 0 0 258246973 Jul 24 02:12 docker_images.zip
drwxr-xr-x 2 0 0 4096 Jul 24 02:13 repodata
lftp 192.168.6.254:/public> bye
[root@docker01 ~]# ls
anaconda-ks.cfg docker_images.zip RPM-GPG-KEY-CentOS-7
busybox.tar ifcfg-eth0
[root@docker01 ~]# unzip docker_images.zip
-bash: unzip: command not found
[root@docker01 ~]# yum -y install unzip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package unzip.x86_64 0:6.0-16.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
unzip x86_64 6.0-16.el7 local_source 169 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 169 k
Installed size: 365 k
Downloading packages:
unzip-6.0-16.el7.x86_64.rpm | 169 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : unzip-6.0-16.el7.x86_64 1/1
Verifying : unzip-6.0-16.el7.x86_64 1/1
Installed:
unzip.x86_64 0:6.0-16.el7
Complete!
[root@docker01 ~]# unzip docker_images.zip
Archive: docker_images.zip
creating: docker_images/
inflating: docker_images/nginx.tar
inflating: docker_images/redis.tar
inflating: docker_images/centos.tar
inflating: docker_images/registry.tar
inflating: docker_images/ubuntu.tar
[root@docker01 ~]# cd docker_images
[root@docker01 docker_images]# ls
centos.tar nginx.tar redis.tar registry.tar ubuntu.tar
[root@docker01 docker_images]# du -sh *
198M centos.tar
181M nginx.tar
181M redis.tar
35M registry.tar
79M ubuntu.tar
[root@docker01 docker_images]# ls
centos.tar nginx.tar redis.tar registry.tar ubuntu.tar
[root@docker01 docker_images]# for i in *;do
> docker load < ${i}
> done
[ 5220.792174] XFS (dm-1): Mounting V5 Filesystem
[ 5220.859319] XFS (dm-1): Ending clean mount
43e653f84b79: Loading layer 207.2 MB/207.2 MB
[root@docker01 docker_images]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 22c2dd5ee85d 7 days ago 1.163 MB
ubuntu latest 452a96d81c30 12 weeks ago 79.62 MB
centos latest e934aafc2206 3 months ago 198.6 MB
registry latest d1fd7d86a825 6 months ago 33.26 MB
nginx latest a5311a310510 21 months ago 181.4 MB
redis latest 1aa84b1b434e 22 months ago 182.8 MB