tubaobaoya3 发表于 2019-2-20 06:41:12

Docker镜像管理基础

  Docker image
  含义:含有启动容器所需要的文件系统及内容,因此用其创建并启动docker容器
  1、采用分层构建机制,最底层为bootfs,其之为rootfs
  2、bootfs用于系统引导的文件系统,包括bootloader和kernel,容器启动完成后会被卸载以节约内存资源
  3、rootfs位于bootfs之上,表现为docker容器的根文件系统
  4、传统模式中,系统启动之时,内核挂载rootfs时会首先将其挂载为“只读”模式,完整性自检完成后将其重新挂载为读写模式;
  5、docker中,rootfs有内核挂载为“只读”模式,而后通过“联合挂载”技术额外挂载一个“可写”层;
  镜像生成途径
  1、Dockerfile
  2、基于容器制作
  3、Docker Hub automated builds
  docker commit命令用法
  # docker commit --help
      Usage:docker commit CONTAINER ]
      Create a new image from a container's changes
      Options:
          -a, --author string    Author (e.g., "John Hannibal Smith ")
          -c, --change list      Apply Dockerfile instruction to the created image
          -m, --message string   Commit message
          -p, --pause            Pause container during commit (default true)


  一,基于容器制作镜像

  使用busybox启动一个容器
  # docker run --name httpd -it busybox
  / # mkdir /data/html -p
  / # cd /data/html/
  /data/html # echo "web1 server page." > /data/html/index.htmlhttp://s1.运维网.com/images/20190131/1548948902247290.png
  制作镜像
  # docker commit -a "liheng " -c 'CMD ["/bin/httpd","-f","-h","/data/html"]' -p httpd liheng/httpd:v1
  sha256:c9449a0dfb67341154bd1ac285d7a5dac4bdb19925eeee4dbac218eddbd47b84       http://s1.运维网.com/images/20190131/1548949680686942.png
  # docker images
  REPOSITORY          TAG               IMAGE ID            CREATED             SIZE
  liheng/httpd      v1                  c9449a0dfb67      13 seconds ago      1.2MB
  busybox             latest            3a093384ac30      4 weeks ago         1.2MB
  # docker images --no-trunc
  REPOSITORY          TAG               IMAGE ID                                                                  CREATED             SIZE
  liheng/httpd      v1                  sha256:c9449a0dfb67341154bd1ac285d7a5dac4bdb19925eeee4dbac218eddbd47b84   17 minutes ago      1.2MB
  busybox             latest            sha256:3a093384ac306cbac30b67f1585e12b30ab1a899374dabc3170b9bca246f1444   4 weeks ago         1.2MB
http://s1.运维网.com/images/20190131/1548949782613495.pnghttp://s1.运维网.com/images/20190131/1548949877853946.png
  使用制作的镜像创建容器测试
  # docker run --name httpd1 -d liheng/httpd:v1
  b597aa1740d114d7d09f16eda76e3a2ef1d6847a2b335c71995fe8d0689bb443
  # docker exec -it httpd1 /bin/sh
  / # ps
  PID   USER   TIMECOMMAND
  1 root      0:00 /bin/httpd -f -h /data/html
  12 root      0:00 /bin/sh
  17 root      0:00 ps
http://s1.运维网.com/images/20190131/1548950307900103.pnghttp://s1.运维网.com/images/20190131/1548950347475963.png
http://s1.运维网.com/images/20190131/1548950376808233.png
  docker host主机上访问测试
http://s1.运维网.com/images/20190201/1548950454908874.png
  二、从镜像仓库拉取镜像

  dockerpull   nginx

  拉取完成后,使用拉取的镜像启动一个容器

  docker run --name nginx -d -p 80:80 nginx:latest
  访问测试
http://s1.运维网.com/images/20190201/1548951325606620.png
  

  




页: [1]
查看完整版本: Docker镜像管理基础