Docker基本用法&安装部署

什么是Docker

docker中的容器:
lxc --> libcontainer --> runC

在这里插入图片描述

OCI和OCF

OCI

Open Container-initiative

  • 由Linux基金会主导于2015年6月创立
  • 旨在围绕容器格式和运行时制定一个开放的工业化标准
  • contains two specifications (包含两个规格)
    the Runtime Specification(runtime-spec)(运行规范)
    the Image Specification(image-spec)(形象规范)

OCF

Open Container Format(打开容器格式)
runC is a CLI tool for spawning and running containers according to the OCI specification(runC是一个CLI工具,用于根据OCI规范生成和运行容器)

  • Containers are started as a child process of runC and can be embedded into various other systems without having to run a daemon(容器作为runC的子进程启动,可以嵌入到各种其他系统中,而不需要运行守护进程)
  • runC is built on libcontainer, the same container technology powering millions of Docker Engine installations(runC是基于libcontainer构建的,同样的容器技术为数百万的Docker引擎安装提供了动力)

Docker提供了一个专门容纳镜像的站点,可以个人上传打包好的镜像:https://hub.docker.com/

Docker架构

在这里插入图片描述
现实工作中Client客户端和Docker_HOST服务端是在一台主机上的,是不会使用本地docker管理其他主机上的容器的。
Registry:这个是容器仓库,里面放着各种软件的容器仓库,软件容器仓库中又放着各种版本的镜像文件。

镜像是静态的,而容器是动态的,容器有其生命周期,镜像与容器的关系类似于程序与进程的关系。镜像类似于文件系统中的程序文件,而容器则类似于将一个程序运行起来的状态,也即进程。所以容器是可以删除的,容器被删除后其镜像是不会被删除的。

Docker对象

When you use docker, you are creating and using images, containers, networks, volumes, pluginns, and other objects.(当你使用Docker容器时,你可以创建和使用图像、容器、网络、卷、插件和其他对象)

IMAGES(镜像)

  • An image is a read-only template with instructions for creating a docker container.(镜像是一个只读的,用来创建容器的模板)

  • Often, an image is based on another image, with some additional customization.(通常,一个镜像是基于另外一个镜像的做的,加上一些自定义的操作)

  • You might create your own images or you might only use those created by others and published in a registry.(您可以创建自己的映像,也可以只使用其他人创建并在注册表中发布在官网仓库中的镜像)
    CONTAINERS(容器)

  • A conntainer is a runnable instance of an image.(一个容器时一个镜像运行起来生成的)

  • You can create, run, stop, move, or delete a container using the docker API or CLI.(您可以通过docker AP(一种接口)I或CLI(命令行功能)创建、运行、停止、移动或删除容器。)

  • You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.(你可以连接一个容器到一个或多个网络,附加存储到里面,就是将容器的数据挂载到那个存储中不放在本地。基于当前的状态创建一个镜像,这里的状态是指安装了某一个服务的情况下创建一个镜像)

Docker的安装和使用

Docker的安装

下载docker的repo源仓库

[root@localhost yum.repos.d]# ls
CentOS-Stream-AppStream.repo         epel-modular.repo
CentOS-Stream-BaseOS.repo            epel-next.repo
CentOS-Stream-Debuginfo.repo         epel-next-testing.repo
CentOS-Stream-Extras.repo            epel-playground.repo
CentOS-Stream-HighAvailability.repo  epel.repo
CentOS-Stream-Media.repo             epel-testing-modular.repo
CentOS-Stream-PowerTools.repo        epel-testing.repo
CentOS-Stream-RealTime.repo

//从网上下载docker源
[root@localhost yum.repos.d]# curl -o docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:-  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:-100  1919  100  1919    0     0    692      0  0:00:02  0:00:02 --:--:--   692
[root@localhost yum.repos.d]# ls
CentOS-Stream-AppStream.repo         docker-ce.repo     //下载好的docker的repo源仓库
CentOS-Stream-BaseOS.repo            epel-modular.repo
CentOS-Stream-Debuginfo.repo         epel-next.repo
CentOS-Stream-Extras.repo            epel-next-testing.repo
CentOS-Stream-HighAvailability.repo  epel-playground.repo
CentOS-Stream-Media.repo             epel.repo
CentOS-Stream-PowerTools.repo        epel-testing-modular.repo
CentOS-Stream-RealTime.repo          epel-testing.repo


//跟改repo的内容,把国外地址改成国内地址
[root@localhost yum.repos.d]# sed -i 's@https://download.docker.com@https://mirrors.tuna.tsinghua.edu.cn/docker-ce@g' docker-ce.repo


//安装docker
[root@localhost ~]# yum  -y install docker-ce

Docker加速

docker-ce的配置文件是/etc/docker/daemon.json,此文件默认不存在,需要我们手动创建并进行配置,而docker的加速就是通过配置此文件来实现的。刚安装完成后默认是没有这个文件路径,但是启动docker后悔自动在/etc/下生成docker目录,但是没有文件,这个文件需要我们自己手动创建。
docker的加速有多种方式:

  • docker cn
  • 中国科技大学加速器
  • 阿里云加速器(需要通过阿里云开发者平台注册帐号,免费使用个人私有的加速器)

这里我们演示使用阿里云云加速器

启动容器

//启动并设置为开机自启,这样就会在etc下生成docker这个目录。
[root@localhost ~]# systemctl enable --now docker.service 
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@localhost ~]# ls /etc/docker/
key.json

第一步:
注册一个阿里云账号,如果已经有账户从第二步开始,直接登陆即可。
在这里插入图片描述第二步:
登陆账户
在这里插入图片描述在这里插入图片描述

第三步:
首先点击控制台然后再点击最左侧的菜单,在里面找到容器镜像服务点击进去
在这里插入图片描述
第四步:
同样在左侧点击镜像工具中的加速器,然后选择合适的系统类型,然后按照区域②中官网的指导配置即可。
在这里插入图片描述

cat > /etc/docker/daemon.json <<EOF
{
    "registry-mirrors": ["https://yeqglrmy.mirror.aliyuncs.com"]
}
EOF

//重新启动docker
[root@localhost ~]# systemctl restart docker

//查看docker版本号信息
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        dea9396
 Built:             Thu Nov 18 00:36:58 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.11
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       847da18
  Built:            Thu Nov 18 00:35:20 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0


//查看docker的信息
[root@localhost ~]# 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.3-docker)
  scan: Docker Scan (Docker Inc., v0.9.0)

Server:
 Containers: 0    
  Running: 0     //运行的容器
  Paused: 0       //停止的容器
  Stopped: 0     //暂停的容器
 Images: 0       //已有的镜像个数
 Server Version: 20.10.11
 Storage Driver: overlay2
  Backing Filesystem: xfs   //存储文件类型
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 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: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.18.0-257.el8.x86_64
 Operating System: CentOS Stream 8    //系统
 OSType: linux
 Architecture: x86_64    //系统平台
 CPUs: 2    //CPU
 Total Memory: 3.901GiB    //内容大小
 Name: localhost.localdomain
 ID: H2T3:GDHL:XY6Q:ODU4:5WP2:Q26N:G6LU:XJ4I:DHVH:PCQO:DEFE:XSKM
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:      //加速的地址
  https://yeqglrmy.mirror.aliyuncs.com/
 Live Restore Enabled: false


Docker常用操作

命令功能
docker searchSearch the Docker Hub for images(在docker hub官网上搜索镜像)
docker pullPull an image or a repository from a registry(从registry也就是官网拉取一个镜像到本地来)
docker imagesList images (列出本地镜像)
docker createCreate a new conntainer (创建一个容器,镜像可以是本地的也可以是网络上的)
docker startStart one or more stopped containers(启动容器)
docker runRun a command in a new container(创建一个容器,并且创建后就自动启动)
docker attachAttach to a runninng container (附加到容器,并让容器在前台运行,但是不能做任何操作)
docker psList containers(查看此时正在运行的容器)
docker logsFetch the logs of a container (查看容器的日志)
docker restartRestart a container(重启容器)
docker stopStop one or more running containers (停止容器 -15)
docker killKill one or more running containers(强制杀死容器) -9
docker rmRemove onne or more containers (删除容器)
docker execRun a command in a running container (进入到容器,)
docker infoDisplay system-wide information(查看docker的信息)
docker inspectReturn low-level information on Docker objects(显示容器的详细信息)
  • docker search
[root@localhost ~]# docker search nginx
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                             Official build of Nginx.                        15899     [OK]       
jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con…   2098                 [OK]
richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable of…   819                  [OK]
jc21/nginx-proxy-manager          Docker container for managing Nginx proxy ho…   285                  
linuxserver/nginx                 An Nginx container, brought to you by LinuxS…   160                  
......
......
## STARS受欢迎程度   OFFICIAL官方提供
  • docker pull
    从官网拉取一个镜像,如果不指定版本号,那么就拉取最新版本的
[root@localhost ~]# docker pull  nginx
Using default tag: latest
latest: Pulling from library/nginx
eff15d958d66: Pull complete 
1e5351450a59: Pull complete 
2df63e6ce2be: Pull complete 
9171c7ae368c: Pull complete 
020f975acd28: Pull complete 
266f639b35ad: Pull complete 
Digest: sha256:097c3a0913d7e3a5b01b6c685a60c03632fc7a2b50bc8e35bcaa3691d788226e
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

  • docker images
    列出本地的镜像
[root@localhost ~]# docker images 
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    ea335eea17ab   2 weeks ago   141MB

  • docker create
    创建一个容器,如果本地没有就从网路上拉取一个
[root@localhost ~]# docker create nginx
7ff021ca1387c957d576e1c37eee73fd6e7d2e5c5670062499714f190c48df0a

//网络上拉取
[root@localhost ~]# docker create busybox
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
3aab638df1a9: Pull complete 
Digest: sha256:52817dece4cfe26f581c834d27a8e1bcc82194f914afe6d50afad5a101234ef1
Status: Downloaded newer image for busybox:latest
99e09feb5beddea3ef6a1efcc98ae60eb3ccea48d3c2a7de6825d1d9d50e83dc
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
busybox      latest    d23834f29b38   31 hours ago   1.24MB
nginx        latest    ea335eea17ab   2 weeks ago    141MB

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS         PORTS     NAMES
99e09feb5bed   busybox   "sh"                     About a minute ago   Created                  hopeful_bouman
  • docker start
    启动容器
[root@localhost ~]# docker ps -a   //列出本地所有的容器,包括停止和运行中的
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS    PORTS     NAMES
7ff021ca1387   nginx     "/docker-entrypoint.…"   16 seconds ago   Created             determined_moore

[root@localhost ~]# docker start 7ff021ca1387   //启动ID为7ff021ca1387  nginx的容器
7ff021ca1387

[root@localhost ~]# docker ps   //列出本地在运行的容器
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS     NAMES
7ff021ca1387   nginx     "/docker-entrypoint.…"   5 minutes ago   Up 2 minutes   80/tcp    determined_moore


  • docker restart
    重新启动容器
[root@localhost ~]# docker restart 7ff021ca1387
7ff021ca1387
[root@localhost ~]# docker ps 
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS        PORTS     NAMES
7ff021ca1387   nginx     "/docker-entrypoint.…"   6 minutes ago   Up 1 second   80/tcp    determined_moore
## 1秒前启动
  • docker attach
    让容器在前台运行,此时是不能做任何操作的,如果这个时候退出则服务也会退出停止
[root@localhost ~]# docker attach 7ff021ca1387


# Ctrl+c退出

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES


  • docker run

选项:

-a, --attach=[] 登录容器(以docker run -d启动的容器)
-c, --cpu-shares=0 设置容器CPU权重,在CPU共享场景使用
–cap-add=[] 添加权限
–cap-drop=[] 删除权限
–cidfile="" 运行容器后,在指定文件中写入容器PID值,一种典型的监控系统用法
–cpuset="" 设置容器可以使用哪些CPU,此参数可以用来容器独占CPU
-d, --detach=false 指定容器运行于前台还是后台
–device=[] 添加主机设备给容器,相当于设备直通
–dns=[] 指定容器的dns服务器
–dns-search=[] 指定容器的dns搜索域名,写入到容器的/etc/resolv.conf文件
-e, --env=[] 指定环境变量,容器中可以使用该环境变量
–entrypoint="" 覆盖image的入口点
–env-file=[] 指定环境变量文件,文件格式为每行一个环境变量
–expose=[] 指定容器暴露的端口,即修改镜像的暴露端口
-h, --hostname="" 指定容器的主机名
-i, --interactive=false 打开STDIN,用于控制台交互
–link=[] 指定容器间的关联,使用其他容器的IP、env等信息
–lxc-conf=[] 指定容器的配置文件,只有在指定–exec-driver=lxc时使用
-m, --memory="" 指定容器的内存上限
–name="" 指定容器名字,后续可以通过名字进行容器管理,links特性需要使用名字
–net=“bridge” 容器网络设置,待详述
-P, --publish-all=false 指定容器暴露的端口,待详述
-p, --publish=[] 指定容器暴露的端口,待详述
–privileged=false 指定容器是否为特权容器,特权容器拥有所有的capabilities
–restart="" 指定容器停止后的重启策略,待详述
–rm=false 指定容器停止后自动删除容器(不支持以docker run -d启动的容器)
–sig-proxy=true 设置由代理接受并处理信号,但是SIGCHLD、SIGSTOP和SIGKILL不能被代理
-t, --tty=false 分配tty设备,该可以支持终端登录
-u, --user="" 指定容器的用户
-v, --volume=[] 给容器挂载存储卷,挂载到容器的某个目录
–volumes-from=[] 给容器挂载其他容器上的卷,挂载到容器的某个目录
-w, --workdir="" 指定容器的工作目录

[root@localhost ~]# docker run -it busybox /bin/sh
/ # ls
bin   dev   etc   home  proc  root  sys   tmp   usr   var
/ # ls ~
/ # 
/ # exit

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                          PORTS     NAMES
034c370b6397   busybox   "/bin/sh"                2 minutes ago    Exited (0) About a minute ago             vibrant_mclaren

  • docker info
root@localhost ~]# 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.3-docker)
  scan: Docker Scan (Docker Inc., v0.9.0)

Server:
 Containers: 0    
  Running: 0     //运行的容器
  Paused: 0       //停止的容器
  Stopped: 0     //暂停的容器
 Images: 0       //已有的镜像个数
 Server Version: 20.10.11
 Storage Driver: overlay2
  Backing Filesystem: xfs   //存储文件类型
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 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: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.18.0-257.el8.x86_64
 Operating System: CentOS Stream 8    //系统
 OSType: linux
 Architecture: x86_64    //系统平台
 CPUs: 2    //CPU
 Total Memory: 3.901GiB    //内容大小
 Name: localhost.localdomain
 ID: H2T3:GDHL:XY6Q:ODU4:5WP2:Q26N:G6LU:XJ4I:DHVH:PCQO:DEFE:XSKM
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:      //加速的地址
  https://yeqglrmy.mirror.aliyuncs.com/
 Live Restore Enabled: false
  • docker rm
    删除容器,rm后面可以跟容器ID 或者一下方式删除所有没有在运行的容器。需要注意的是删除容器只能删除不在运行的,如果容器在运行需要先停止再删除,或者docker rm -f 强制删除-f
[root@localhost ~]# docker rm $(docker ps -aq)
f3f7a8568962
034c370b6397
cf00ddaac86e
72a3728d218d
99e09feb5bed
7ff021ca1387

[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

  • docker inspect
    查看容器的详细详细
[root@localhost ~]# docker inspect 38a57540c5b2
[
    {
        "Id": "38a57540c5b2277be606c5a3a2b98b0f2f71bb474c4f6eeaf8d6f1c31347457b",
        "Created": "2021-12-01T12:07:13.225060036Z",
        "Path": "httpd-foreground",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
......
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",   //容器的IP地址
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

//访问容器,因为这是httpd服务容器 所以会有内容
[root@localhost ~]# curl 172.17.0.2
<html><body><h1>It works!</h1></body></html>

  • docker logs
    查看容器的日志文件
[root@localhost ~]# docker logs 38a57540c5b2
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Wed Dec 01 12:07:35.666179 2021] [mpm_event:notice] [pid 1:tid 139798211771712] AH00489: Apache/2.4.51 (Unix) configured -- resuming normal operations
[Wed Dec 01 12:07:35.695263 2021] [core:notice] [pid 1:tid 139798211771712] AH00094: Command line: 'httpd -D FOREGROUND'
172.17.0.1 - - [01/Dec/2021:12:12:29 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [01/Dec/2021:12:14:12 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [01/Dec/2021:12:14:13 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [01/Dec/2021:12:14:13 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [01/Dec/2021:12:14:14 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [01/Dec/2021:12:14:15 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [01/Dec/2021:12:14:15 +0000] "GET / HTTP/1.1" 200 45    //前面访问这个http服务的记录

  • exec
    进入到容器中(最常用),并且exec也不会停止运行,也就是后台运行
[root@localhost ~]# docker exec -it 38a57540c5b2 /bin/bash    
## -it交互模式进去  
root@38a57540c5b2:/usr/local/apache2# ls
bin    cgi-bin  error   icons    logs
build  conf     htdocs  include  modules
root@38a57540c5b2:/usr/local/apache2# cd bin/
root@38a57540c5b2:/usr/local/apache2/bin# ls
ab         dbmmanage    htcacheclean  httpd       suexec
apachectl  envvars      htdbm         httxt2dbm
apxs       envvars-std  htdigest      logresolve
checkgid   fcgistarter  htpasswd      rotatelogs

  • docker info → 显示系统范围的信息
[root@localhost ~]# 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.3-docker)
  scan: Docker Scan (Docker Inc., v0.9.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.11
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 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: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-862.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 1.779GiB
 Name: localhost.localdomain
 ID: BYNG:CDGP:V62W:5NS4:CQPZ:ZCHU:N2YY:DMF6:CDVT:WMOJ:ZQW4:D7IP
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

  • docker inspect → 返回有关Docker对象的详细信息
[root@localhost ~]# docker inspect 2dd4b4019147
[
    {
        "Id": "2dd4b4019147f7409a5bb78869a508149c15e6449412323076564df76f1d12d0",
        "Created": "2021-12-01T14:58:17.480606425Z",
        "Path": "httpd-foreground",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 40723,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-12-01T14:58:17.767659939Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:ad17c88403e2cedd27963b98be7f04bd3f903dfa7490586de397d0404424936d",
        "ResolvConfPath": "/var/lib/docker/containers/2dd4b4019147f7409a5bb78869a508149c15e6449412323076564df76f1d12d0/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/2dd4b4019147f7409a5bb78869a508149c15e6449412323076564df76f1d12d0/hostname",
        "HostsPath": "/var/lib/docker/containers/2dd4b4019147f7409a5bb78869a508149c15e6449412323076564df76f1d12d0/hosts",
        "LogPath": "/var/lib/docker/containers/2dd4b4019147f7409a5bb78869a508149c15e6449412323076564df76f1d12d0/2dd4b4019147f7409a5bb78869a508149c15e6449412323076564df76f1d12d0-json.log",
        "Name": "/infallible_thompson",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/59806da4fa41ad1fabf77b620307211cd490f177e1ce9e593084ca01a06a12c2-init/diff:/var/lib/docker/overlay2/36ed93e176c0efdde307d3bc1d79afde06b98ce5d55e8a5559f9d52898fa700f/diff:/var/lib/docker/overlay2/da05fe4a138adfa74195fbe6b7d48a1e33b7bdef9991dc56f0d41c9dce0dee6c/diff:/var/lib/docker/overlay2/9c7068052b46318736e32d7e970398f0fe7df8a749201bcf60c692f410cba13d/diff:/var/lib/docker/overlay2/1953bf937cd0997d8b717ca69f3c0384de3497ff7292af506c90eb4d371ad2d0/diff:/var/lib/docker/overlay2/c69f8634857d44cd89525b782bd5c39014984e753f7ebc5b6c3e661577c87b3b/diff",
                "MergedDir": "/var/lib/docker/overlay2/59806da4fa41ad1fabf77b620307211cd490f177e1ce9e593084ca01a06a12c2/merged",
                "UpperDir": "/var/lib/docker/overlay2/59806da4fa41ad1fabf77b620307211cd490f177e1ce9e593084ca01a06a12c2/diff",
                "WorkDir": "/var/lib/docker/overlay2/59806da4fa41ad1fabf77b620307211cd490f177e1ce9e593084ca01a06a12c2/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "2dd4b4019147",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/apache2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "HTTPD_PREFIX=/usr/local/apache2",
                "HTTPD_VERSION=2.4.51",
                "HTTPD_SHA256=20e01d81fecf077690a4439e3969a9b22a09a8d43c525356e863407741b838f4",
                "HTTPD_PATCHES="
            ],
            "Cmd": [
                "httpd-foreground"
            ],
            "Image": "httpd",
            "Volumes": null,
            "WorkingDir": "/usr/local/apache2",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {},
            "StopSignal": "SIGWINCH"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "08e39e54dcab30e7d01e8dd0c9d69668a39e2afab86cd846fad09e217fbb8b50",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/08e39e54dcab",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "15b1dcd50fb8583744379ec7a65a6bbccf8e4fe76c81ef57ebdf36e817395f6f",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.4",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:04",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "1e342ac6b2af20d51aa467e89ce0d41f754e4daca47beb34de0a6c0de81750d2",
                    "EndpointID": "15b1dcd50fb8583744379ec7a65a6bbccf8e4fe76c81ef57ebdf36e817395f6f",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.4",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:04",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@localhost ~]# curl 172.17.0.4
<html><body><h1>It works!</h1></body></html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值