四、Docker镜像(image)
- docker采用分层构建机制,最底层为bootfs,次之为rootfs
- bootfs: 用于系统引导的文件系统,包括BootLoader和kernel,容器启动完成后会被卸载以节约内存资源
- rootfs: 位于bootfs之上,表现为docker容器的根文件系统,docker采用联合挂载,每一层都是只读的,在最上层有一个可写层
- Aufs:高级多层统一文件系统,由Junjiro Okajima开发,早期使用
- overlayfs & overlay2fs:至3.18版本开始被合并到Linux内核
# docker info |grep "Storage Driver"Storage Driver: overlay2
Sponsor RegistryMirror RegistryVendor RegistryPrivate Registry
Image Repositories 镜像仓库Automated Build 自动构建Webhooks 可以将GitHub中的dockerfile自动构建为镜像Organizations 组织GitHub and Bitbucket integration
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
- 手工组织文件系统,打包成docker image
- 基于容器制作,在运行的容器上commit将可写层制作成image
- 基于Dockerfile手动build或者自动构建,Dockerfile基于Base image制作
# docker pull centos:centos7.5.1804# docker run --name centos -it centos:centos7.5.1804[root@xxxxxxxxxxx /]# yum install vim wget lftp bash-completion net-tools bind-utils telnet screen tree psmisc bc httpd -y# docker commit -p centos# docker image ls 484173886091 22 seconds ago 362MB# docker tag 484173886091 dongfeimg/mycentos:v0.1# docker image lsdongfeimg/mycentos v0.1 484173886091 5 minutes ago 362MB
# docker run --name mycentos -it dongfeimg/mycentos:v0.1[root@3c21ac1d0496 /]# mkdir -p /data/html/[root@3c21ac1d0496 /]# vim /var/www/html/index.htmlWelcome Dongfei website.
# docker commit -a "Dongfei" -c 'CMD ["/usr/bin/systemctl","start","httpd"]' -p mycentos dongfeimg/mycentos:v0.2# docker run --name mycentos2 --privileged=true -d dongfeimg/mycentos:v0.2 /usr/sbin/init[root@docker ~]# docker exec -it 7cec67f74460 bash[root@7cec67f74460 /]# systemctl start httpd# docker inspect 7cec67f74460 |grep IPAddress"IPAddress": "172.17.0.4",# curl 172.17.0.4Welcome Dongfei website.
# docker loginLogin with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.Username: dongfeimgPassword: ******WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded# docker push dongfeimg/mycentos:v0.1# docker push dongfeimg/mycentos:v0.2
# docker save -o myimages.gz centos:centos7.5.1804 dongfeimg/mycentos:v0.1# docker load -i myimages.gz
# docker save $(docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}') -o images_name.gz