day0---docker容器镜像常用操作(2)

一、测试docker服务是否正常

docker info命令查看docker的相关信息

docker info 也可以看到当前安装的系统是否正常

[root@hdss7-11 ~]# docker info
Client:
 Context:    default
 Debug Mode: false    ##调试模式
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Containers: 0     #目前的容器
  Running: 0       #正在运行的容器
  Paused: 0        #暂停的服务
  Stopped: 0       #关闭的服务
 Images: 0         #镜像
 Server Version: 20.10.8     ##版本信息
 Storage Driver: overlay2    #所使用存储引擎是overlay2
  Backing Filesystem: xfs    #底层的操作系统是xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd        #驱动是
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e25210fe30a0a703442421b0f60afac609f950a3
 runc version: v1.0.1-0-g4144b63
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-957.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 4                  #整个机器是4核的cpu
 Total Memory: 3.683GiB    #4g的内存
 Name: hdss7-11.host.com
 ID: TXHZ:DSIP:A47A:6JCW:VUE5:IDGJ:JTN3:ARJC:TNE3:OLAP:2L7Z:4KNH
 Docker Root Dir: /data/docker    #docker的目录放在点
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  quay.io
  registry.access.redhat.com
  hardor.od.com
  127.0.0.0/8
 Registry Mirrors:
  https://7lkjwk2y.mirror.aliyuncs.com/
 Live Restore Enabled: true

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled


查看版本信息
[root@hdss7-11 ~]# docker version

用docker run启动一个容器

[root@hdss7-11 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally   #不能在本地找到
latest: Pulling from library/hello-world   #去下载一个镜像
b8dfde127a29: Pull complete 
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Status: Downloaded newer image for hello-world:latest   #下载完成

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

二、docker 核心的三个概念和注册docker.hub

容器—仓库—镜像

如下图–右边表示三个概念之间是如何进行交互的
day0---docker容器镜像常用操作(2)_第1张图片

registry_name  		    指的是仓库名称
repository_name   	    指的的二级仓库的名称
image_name  			指的是镜像名称
tag_name    			指的的是镜像的标签

下面是自己去注册一个dockerhub的注册

注册地址:https://hub.docker.com/
里面是全球最大的docker社区,里面有官方提供的镜像
注册过程
1、点击注册
day0---docker容器镜像常用操作(2)_第2张图片
2、填写注册信息,勾选相关选项
day0---docker容器镜像常用操作(2)_第3张图片
3、填写信息后进程相关的选择
day0---docker容器镜像常用操作(2)_第4张图片
4、下面是告诉你到邮件去通过注册
day0---docker容器镜像常用操作(2)_第5张图片
5、到自己的邮箱进程进一步注册–验证
day0---docker容器镜像常用操作(2)_第6张图片
6、下面就是告诉你验证成功了
day0---docker容器镜像常用操作(2)_第7张图片
7、然后进行登录即可
day0---docker容器镜像常用操作(2)_第8张图片
8、登录成功后就可以看到自己的用户中心了
下面是我注册的一个登录界面
day0---docker容器镜像常用操作(2)_第9张图片
day0---docker容器镜像常用操作(2)_第10张图片
下面所几个经常可能会用到的点
My Profile 我的用户档案
Repositories 存储库里面有你上传过的镜像
你可以把自己代码托管到docker.hub上但是免费的必须公开

三、登录在后台登录到自己的仓库进行操作

登录方式

[root@hdss7-11 ~]# docker login docker.io
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: yunduan666       #输入自己的注册名称
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的登录信息的文件不要泄露。
day0---docker容器镜像常用操作(2)_第11张图片

搜索一个镜像

命令行搜索
如alpine最小的一个发型版可以看到一堆镜像

[root@hdss7-11 ~]# docker search alpine
NAME                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
alpine                                 A minimal Docker image based on Alpine Linux…   7730      [OK]       
mhart/alpine-node                      Minimal Node.js built on Alpine Linux           483                  
anapsix/alpine-java                    Oracle Java 8 (and 7) with GLIBC 2.28 over A…   472                  [OK]
frolvlad/alpine-glibc                  Alpine Docker image with glibc (~12MB)          266                  [OK]
alpine/git                             A  simple git container running in alpine li…   188                  [OK]
yobasystems/alpine-mariadb             MariaDB running on Alpine Linux [docker] [am…   94                   [OK]
alpine/socat                           Run socat command in alpine container           73                   [OK]
davidcaste/alpine-tomcat               Apache Tomcat 7/8 using Oracle Java 7/8 with…   44                   [OK]
kiasaki/alpine-postgres                PostgreSQL docker image based on Alpine Linux   44                   [OK]
jfloff/alpine-python                   A small, more complete, Python Docker image …   41                   [OK]
zenika/alpine-chrome                   Chrome running in headless mode in a tiny Al…   34                   [OK]
byrnedo/alpine-curl                    Alpine linux with curl installed and set as …   34                   [OK]
hermsi/alpine-sshd                     Dockerize your OpenSSH-server with rsync and…   34                   [OK]
hermsi/alpine-fpm-php                  FPM-PHP 7.0 to 8.0, shipped along with tons …   25                   [OK]
etopian/alpine-php-wordpress           Alpine WordPress Nginx PHP-FPM WP-CLI           25                   [OK]
bashell/alpine-bash                    Alpine Linux with /bin/bash as a default she…   18                   [OK]
roribio16/alpine-sqs                   Dockerized ElasticMQ server + web UI over Al…   15                   [OK]
davidcaste/alpine-java-unlimited-jce   Oracle Java 8 (and 7) with GLIBC 2.21 over A…   13                   [OK]
spotify/alpine                         Alpine image with `bash` and `curl`.            11                   [OK]
cfmanteiga/alpine-bash-curl-jq         Docker Alpine image with Bash, curl and jq p…   6                    [OK]
dwdraju/alpine-curl-jq                 Alpine Docker Image with curl, jq, bash         1                    [OK]
ellerbrock/alpine-mysql-client         MySQL Client based on Alpine Linux              1                    [OK]
bushrangers/alpine-caddy               Alpine Linux Docker Container running Caddys…   1                    [OK]
apteno/alpine-jq                       Weekly build of alpine image with curl, wget…   1                    
goodguykoi/alpine-curl-internal        simple alpine image with curl installed no C…   1                    [OK]

当然也可以去 页面上进行搜索
day0---docker容器镜像常用操作(2)_第12张图片

下载镜像

不加tag指定下载的最新版本

[root@hdss7-11 ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
29291e31a76a: Pull complete 
Digest: sha256:eb3e4e175ba6d212ba1d6e04fc0782916c08e1c9d7b45892e9796141b1d379ae
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

也可以指定版本下载
[root@hdss7-11 ~]# docker pull alpine:3.10.3
3.10.3: Pulling from library/alpine
89d9c30c1d48: Pull complete 
Digest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a
Status: Downloaded newer image for alpine:3.10.3
docker.io/library/alpine:3.10.3

查看镜像
[root@hdss7-11 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
alpine        latest    021b3423115f   42 hours ago    5.6MB
hello-world   latest    d1165f221234   5 months ago    13.3kB
alpine        3.10.3    965ea09ff2eb   21 months ago   5.55MB
[root@hdss7-11 ~]# docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
alpine        latest    021b3423115f   42 hours ago    5.6MB
hello-world   latest    d1165f221234   5 months ago    13.3kB
alpine        3.10.3    965ea09ff2eb   21 months ago   5.55MB


给镜像打标签

[root@hdss7-11 ~]# docker tag 965ea09ff2eb docker.io/yunduan666/alpine:v3.10.3
[root@hdss7-11 ~]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED         SIZE
alpine              latest    021b3423115f   42 hours ago    5.6MB
hello-world         latest    d1165f221234   5 months ago    13.3kB
alpine              3.10.3    965ea09ff2eb   21 months ago   5.55MB
yunduan666/alpine   v3.10.3   965ea09ff2eb   21 months ago   5.55MB

推送镜像

[root@hdss7-11 ~]# docker push docker.io/yunduan666/alpine:v3.10.3

到自己的存储里面就有了你推送的镜像了
day0---docker容器镜像常用操作(2)_第13张图片
注意拉和推镜像默认走的http协议
可以查看自己的推送镜像的tag在hub上面
day0---docker容器镜像常用操作(2)_第14张图片

删除镜像

需要先删除本地的标签
day0---docker容器镜像常用操作(2)_第15张图片
但是你的docker.hub的是不会删除的

四、管理镜像与镜像原理介绍

必须要掌握的docker命令

day0---docker容器镜像常用操作(2)_第16张图片

docker镜像的特性

day0---docker容器镜像常用操作(2)_第17张图片
根据aufs进行构建的,因为docker是一个典型的分成结构
最底层bootfs ———整个docke镜像依赖的库和Kernel(内核)去交互的东西
上面是base images
上面是你加入的比如odd emacs(文本编辑器)
Debian发现版
真正的容器在最上面的Writable最顶层–除了上面下面都是只读的
每次同步的时候都是仅仅推送增量的部分
所以拉去的时候都是拉增量的部分,所以你用担心镜像大

你可能感兴趣的:(docker)