Docker镜像

四、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
  • Docker Registry分类
Sponsor Registry
Mirror Registry
Vendor Registry
Private Registry
  • Docker Hub
Image Repositories  镜像仓库
Automated Build  自动构建
Webhooks  可以将GitHub中的dockerfile自动构建为镜像
Organizations  组织
GitHub and Bitbucket integration
  • docker image
  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)
  1. 手工组织文件系统,打包成docker image
  2. 基于容器制作,在运行的容器上commit将可写层制作成image
  3. 基于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
<none>                   <none>              484173886091        22 seconds ago      362MB
# docker tag 484173886091 dongfeimg/mycentos:v0.1
# docker image ls
dongfeimg/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.html
<h1>Welcome Dongfei website.</h1>
# 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.4
<h1>Welcome Dongfei website.</h1>
  • docker push
# docker login
Login 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: dongfeimg
Password: ******
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login 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 images批量全部打包
# docker save $(docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}') -o images_name.gz
posted @ 2019-06-15 20:22  生生不息.连绵不绝  阅读(252)  评论(0编辑  收藏  举报