• Docker 入门流程


    基础的docker基本命令

    docker启动命令

    [root@localhost ~]# systemctl start docker
    
    • 1

    查询docker 命令帮助

    [root@localhost ~]# docker --help
    
    • 1

    查看镜像

    [root@localhost ~]# docker images
    REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
    mysql         5.7       c20987f18b13   5 months ago   448MB
    mysql         latest    3218b38490ce   5 months ago   516MB
    hello-world   latest    feb5d9fea6a5   7 months ago   13.3kB
    
    • 1
    • 2
    • 3
    • 4
    • 5

    docker 搜索命令 ( 它会去镜像地址去搜索)

    [root@localhost ~]# docker search mysql
    NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    mysql                          MySQL is a widely used, open-source relation…   12606     [OK]       
    mariadb                        MariaDB Server is a high performing open sou…   4843      [OK]       
    percona                        Percona Server is a fork of the MySQL relati…   576       [OK]       
    phpmyadmin                     phpMyAdmin - A web interface for MySQL and M…   542       [OK]       
    bitnami/mysql                  Bitnami MySQL Docker Image                      71                   [OK]
    linuxserver/mysql-workbench                                                    36                   
    linuxserver/mysql              A Mysql container, brought to you by LinuxSe…   35                   
    ubuntu/mysql                   MySQL open source fast, stable, multi-thread…   33                   
    circleci/mysql                 MySQL is a widely used, open-source relation…   26                   
    google/mysql                   MySQL server for Google Compute Engine          21                   [OK]
    rapidfort/mysql                RapidFort optimized, hardened image for mysql   12                   
    vmware/harbor-db               Mysql container for Harbor                      10                   
    bitnami/mysqld-exporter                                                        3                    
    ibmcom/mysql-s390x             Docker image for mysql-s390x                    2                    
    nasqueron/mysql                                                                1                    [OK]
    newrelic/mysql-plugin          New Relic Plugin for monitoring MySQL databa…   1                    [OK]
    vitess/mysqlctld               vitess/mysqlctld                                1                    [OK]
    cimg/mysql                                                                     0                    
    mirantis/mysql                                                                 0                    
    drud/mysql-local-57            ddev mysql local container                      0                    
    drud/mysql-docker-local-57     This repo has been deprecated, new tags are …   0                    
    drud/mysql                                                                     0                    
    drud/mysql-docker-local        docker containers for local womysql rk          0                    [OK]
    docksal/mysql                  MySQL service images for Docksal - https://d…   0                    
    silintl/mysql-backup-restore   Simple docker image to perform mysql backups…   0                    [OK]
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    docker pull 下载镜像

    [root@localhost ~]# docker pull mysql
    Using default tag: latest   		  	 # 如果不写tag. 默认就是latest
    latest: Pulling from library/mysql
    72a69066d2fe: Pull complete     		 # 分层下载,docker imager 的核心 联合文件系统
    93619dbc5b36: Pull complete 
    99da31dd6142: Pull complete 
    626033c43d70: Pull complete 
    37d5d7efb64e: Pull complete 
    ac563158d721: Pull complete 
    d2ba16033dad: Pull complete 
    688ba7d5c01a: Pull complete 
    00e060b6d11d: Pull complete 
    1c04857f594f: Pull complete 
    4d7cfa90e6ea: Pull complete 
    e0431212d27d: Pull complete 
    Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709  #签名
    Status: Downloaded newer image for mysql:latest
    docker.io/library/mysql:latest     #真实地址
    
    
    # 等价于它 以下命令等价
    docker pull mysql
    docker pull docker.io/library/mysql:latest   
    
    # 指定版本下载
    [root@localhost ~]# docker pull mysql:5.7
    5.7: Pulling from library/mysql
    72a69066d2fe: Already exists     #上面已经下载过的mysql镜像,这一次可以共用,所以表示已存在
    93619dbc5b36: Already exists 
    99da31dd6142: Already exists 
    626033c43d70: Already exists 
    37d5d7efb64e: Already exists 
    ac563158d721: Already exists 
    d2ba16033dad: Already exists 
    0ceb82207cd7: Pull complete 
    37f2405cae96: Pull complete 
    e2482e017e53: Pull complete 
    70deed891d42: Pull complete 
    Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
    Status: Downloaded newer image for mysql:5.7
    docker.io/library/mysql:5.7
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41

    docker rmi 删除镜像

    # 查看已有的镜像
    [root@localhost ~]# docker images
    REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
    mysql         5.7       c20987f18b13   5 months ago   448MB
    mysql         latest    3218b38490ce   5 months ago   516MB
    hello-world   latest    feb5d9fea6a5   7 months ago   13.3kB
    
     # 根据镜像的id进行删除
    [root@localhost ~]# docker rmi -f c20987f18b13  
    Untagged: mysql:5.7
    Untagged: mysql@sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
    Deleted: sha256:c20987f18b130f9d144c9828df630417e2a9523148930dc3963e9d0dab302a76
    Deleted: sha256:6567396b065ee734fb2dbb80c8923324a778426dfd01969f091f1ab2d52c7989
    
    # 查看镜像,删除成功
    [root@localhost ~]# docker images
    REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
    mysql         latest    3218b38490ce   5 months ago   516MB
    hello-world   latest    feb5d9fea6a5   7 months ago   13.3kB
    
    # 查询出所有镜像后进行递归删除
    [root@localhost ~]# docker rmi -f $(docker images -aq)
    Untagged: mysql:latest
    Untagged: mysql@sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
    Deleted: sha256:3218b38490cec8d31976a40b92e09d61377359eab878db49f025e5d464367f3b
    Untagged: hello-world:latest
    Untagged: hello-world@sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f390d5acba9741b17
    Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    容器命令

    说明:我们有了镜像才可以创建容器,linux,下载一个centos镜像来测试学习

    [root@localhost ~]# docker pull centos
    Using default tag: latest
    latest: Pulling from library/centos
    
    # 查看镜像, 镜像已经下载成功
    [root@localhost ~]# docker images
    REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
    centos       latest    5d0da3dc9764   8 months ago   231MB
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    1、新建容器并启动
    docker run [可选参数] image    # 可选参数使用 docker run --help  命令查看有哪些
    
    # 参数说明
    --name="name"	容器名字 tomcat01   tomcat02  用来区分容器
    -d 			后台方式运行 
    -it			使用交互方式运行,进入容器查看内容
    -p				指定容器的端口 -p 8080:8080\
    	-p 主机端口:容器端口(常用)
    	-p 容器端口
    -p	随机指定端口
    
    	 		
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    测试:
    启动容器并给名字 为 it
    [root@localhost ~]# docker run -it centos /bin/bash  	
    [root@317beaac0681 /]# 					
    
    • 1
    • 2
    表明已经进入到容器了

    查看启动的容器内部, 可以看出这个容器内容跟普通的容器没啥区别
    [root@317beaac0681 /]# ls
    bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var 
    
    • 1
    • 2
    退出容器
    exit   # 容器停止运行并退出
    ctrl + p + q  # 容器不停止退出
    
    [root@317beaac0681 /]# exit    # 容器停止运行并退出
    
    # ctrl + P + Q  # 容器不停止退出 (在键盘的大写模式下按这几个键)
    [root@4cac2196aa2e /]# [root@localhost ~]# docker ps 
    CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS              PORTS     NAMES
    4cac2196aa2e   centos    "/bin/bash"   13 seconds ago       Up 10 seconds                 peaceful_carver
    64efab6e12e5   centos    "/bin/bash"   About a minute ago   Up About a minute             objective_jackson
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    列出所有运行的容器
    # docker ps 命令 
    -a			# 列出当前正在运行的容器(默认容器),顺带带出历史运行过的容器
    -n=?		# 只显示最近创建的容器
    -q			# 只显示容器的编号
    
    [root@localhost ~]# docker ps -a
    CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                      PORTS     NAMES
    3bd0aed6e189   centos         "/bin/bash"   45 seconds ago   Exited (0) 17 seconds ago             hopeful_williams
    598addfa8720   centos         "/bin/bash"   5 hours ago      Exited (0) 5 hours ago                quirky_agnesi
    317beaac0681   centos         "/bin/bash"   5 hours ago      Exited (130) 5 hours ago              fervent_lalande
    83c174518303   feb5d9fea6a5   "/hello"      46 hours ago     Exited (0) 46 hours ago               thirsty_davinci
    204a0f5e6da0   feb5d9fea6a5   "/hello"      46 hours ago     Exited (0) 46 hours ago               clever_archimedes		
    
     docker ps 
    CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS              PORTS     NAMES
    4cac2196aa2e   centos    "/bin/bash"   13 seconds ago       Up 10 seconds                 peaceful_carver
    64efab6e12e5   centos    "/bin/bash"   About a minute ago   Up About a minute             objective_jackson
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    删除容器
    docker rm 容器id		# 根据容器id删除容器(不能删除正在运行的容器,要强制删除利用 rm -f)
    docker rm -f $(docker ps -aq)	# 删除所有容器
    docker ps -a -q|xargs docker rm	# 删除所有容器
    下面是列子:
    
    # 由于rm 容器id 不能删除正在运行的容器而导致报错
    [root@localhost ~]# docker rm 4cac2196aa2e
    Error response from daemon: You cannot remove a running container 4cac2196aa2e1df5d16f987c560d3dd81dea7cfa1bdb362cc4e4150856421d0b. Stop the container before attempting removal or force remove
    [root@localhost ~]# docker ps -aq
    4cac2196aa2e
    64efab6e12e5
    3bd0aed6e189
    598addfa8720
    317beaac0681
    83c174518303
    204a0f5e6da0
    
    # rm -f 即可删除正在运行的容器 $(docker ps -aq): 查询出所有正在运行的容器
    [root@localhost ~]# docker rm -f $(docker ps -aq)
    4cac2196aa2e
    64efab6e12e5
    3bd0aed6e189
    598addfa8720
    317beaac0681
    83c174518303
    204a0f5e6da0
    [root@localhost ~]# docker ps -aq		
    [root@localhost ~]# 				# 可以看到,容器都被删除掉了
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    启动和停止容器的操作
    docker start 容器id		# 启动容器
    docker restart 容器id	# 重启容器
    docker stop 容器id		# 停止 当前正在运行的容器
    docker kill 			# 强制停止当前容器
    
    下面是例子(需要有历史运行过的容器,才可以使用以上四条命令):
    
    # 先运行一个容器(这里的目的为了能找到历史运行容器id,否则无法使用上面的方式启动容器)
    [root@localhost ~]# docker run -it centos /bin/bash   
    
    # 把该容器退出
    [root@00faae8b4bf2 /]# exit
    exit
    
    # 查看当前正在运行的容器(为空)
    [root@localhost ~]# docker ps
    CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
    
    # 查看历史运行过的容器(可以看到 容器id=00faae8b4bf2。有了该容器id 就可以用以上命令启动或者停止容器了)
    [root@localhost ~]# docker ps -a
    CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS                          PORTS     NAMES
    00faae8b4bf2   centos    "/bin/bash"   19 seconds ago       Exited (127) 8 seconds ago                suspicious_meninsky
    1581a1d0cf0a   centos    "/bin/bash"   About a minute ago   Exited (0) About a minute ago             serene_bouman
    
    # 使用docker start 容器id 命令启动容器
    [root@localhost ~]# docker start 00faae8b4bf2
    00faae8b4bf2
    [root@localhost ~]# docker ps
    CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS         PORTS     NAMES
    00faae8b4bf2   centos    "/bin/bash"   45 seconds ago   Up 4 seconds             suspicious_meninsky
    
    # 使用docker stop 容器id 停止容器
    [root@localhost ~]# docker stop 00faae8b4bf2
    00faae8b4bf2
    [root@localhost ~]# docker ps
    CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
    [root@localhost ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    常用的其他docker 命令

    后台启动容器

    注意: 该条命令启动容器后,使用docker ps 查看,会发现该容器停止了
    原因: docker 容器使用后台运行,就必须要有一个前台的进程,docker 发现没有应用,就会自动停止
    有使用容器就装了一个nginx ,此时容器启动后,发现自己没有提供服务,就会立刻停止,就是没有程序了

    # docker run -d 镜像名
    
    • 1
    查看日志
    docker logs -f -t --tail [要显示的日志条数] 容器id 
    # 自己编写一段shell脚本,循环打印一句话(为了查看日志)
    [root@localhost ~]# docker run -d centos /bin/sh -c "while true;do echo chenxiansheng;sleep 1;done"
    3926294a2cca4431540e8c5aced519f22c0999f9e6466bd96e767cea548c53ae
    [root@localhost ~]# docker ps
    CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS     NAMES
    3926294a2cca   centos    "/bin/sh -c 'while t…"   5 seconds ago   Up 4 seconds             fervent_torvalds
    
    # 查看日志命令
    [root@localhost ~]# docker logs -t -f --tail 5 3926294a2cca
    2022-05-22T06:56:16.970217803Z chenxiansheng
    2022-05-22T06:56:17.983250772Z chenxiansheng
    2022-05-22T06:56:18.994815474Z chenxiansheng
    2022-05-22T06:56:19.998974466Z chenxiansheng
    2022-05-22T06:56:21.003155944Z chenxiansheng
    ^C
    [root@localhost ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    查看容器运行进程信息
    docker top 容器id
    
    # 例子:
    [root@localhost ~]# docker top 3926294a2cca
    UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
    root                1967                1947                0                   14:54               ?                   00:00:00            /bin/sh -c while true;do echo chenxiansheng;sleep 1;done
    root                2845                1967                0                   15:08               ?                   00:00:00            /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    查看镜像的元数据
    docker inspect  
    
    # docker inspect 能使用的命令
    [root@localhost ~]# docker inspect --help
    
    Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]
    
    Return low-level information on Docker objects
    
    Options:
      -f, --format string   Format the output using the given Go template
      -s, --size            Display total file sizes if the type is container
          --type string     Return JSON for specified type
    
    
    下面是使用例子:
    # 可以看到镜像id 是该进程id的前缀
    [root@localhost ~]# docker inspect 3926294a2cca
    [
        {
            "Id": "3926294a2cca4431540e8c5aced519f22c0999f9e6466bd96e767cea548c53ae",
            "Created": "2022-05-22T06:54:51.055490626Z",
            "Path": "/bin/sh",
            "Args": [
                "-c",
                "while true;do echo chenxiansheng;sleep 1;done"
            ],
            "State": {
                "Status": "running",
                "Running": true,
                "Paused": false,
                "Restarting": false,
                "OOMKilled": false,
                "Dead": false,
                "Pid": 1967,
                "ExitCode": 0,
                "Error": "",
                "StartedAt": "2022-05-22T06:54:52.152158173Z",
                "FinishedAt": "0001-01-01T00:00:00Z"
            },
            "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
            "ResolvConfPath": "/var/lib/docker/containers/3926294a2cca4431540e8c5aced519f22c0999f9e6466bd96e767cea548c53ae/resolv.conf",
            "HostnamePath": "/var/lib/docker/containers/3926294a2cca4431540e8c5aced519f22c0999f9e6466bd96e767cea548c53ae/hostname",
            "HostsPath": "/var/lib/docker/containers/3926294a2cca4431540e8c5aced519f22c0999f9e6466bd96e767cea548c53ae/hosts",
            "LogPath": "/var/lib/docker/containers/3926294a2cca4431540e8c5aced519f22c0999f9e6466bd96e767cea548c53ae/3926294a2cca4431540e8c5aced519f22c0999f9e6466bd96e767cea548c53ae-json.log",
            "Name": "/fervent_torvalds",
            "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/e564fca82acaf0d594fea6217e190503e5674ff9909a45429ec75cb0d8ab2d72-init/diff:/var/lib/docker/overlay2/8da0b0258a4c475bbdf2c544b058908a98b9e203ccddd77c36dcad7dc096162a/diff",
                    "MergedDir": "/var/lib/docker/overlay2/e564fca82acaf0d594fea6217e190503e5674ff9909a45429ec75cb0d8ab2d72/merged",
                    "UpperDir": "/var/lib/docker/overlay2/e564fca82acaf0d594fea6217e190503e5674ff9909a45429ec75cb0d8ab2d72/diff",
                    "WorkDir": "/var/lib/docker/overlay2/e564fca82acaf0d594fea6217e190503e5674ff9909a45429ec75cb0d8ab2d72/work"
                },
                "Name": "overlay2"
            },
            "Mounts": [],
            "Config": {
                "Hostname": "3926294a2cca",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ],
                "Cmd": [
                    "/bin/sh",
                    "-c",
                    "while true;do echo chenxiansheng;sleep 1;done"
                ],
                "Image": "centos",
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": null,
                "OnBuild": null,
                "Labels": {
                    "org.label-schema.build-date": "20210915",
                    "org.label-schema.license": "GPLv2",
                    "org.label-schema.name": "CentOS Base Image",
                    "org.label-schema.schema-version": "1.0",
                    "org.label-schema.vendor": "CentOS"
                }
            },
            "NetworkSettings": {
                "Bridge": "",
                "SandboxID": "d80dfcd35589cac557f556bf5f47895d0d7dc9eabf461985c703b240daed0f33",
                "HairpinMode": false,
                "LinkLocalIPv6Address": "",
                "LinkLocalIPv6PrefixLen": 0,
                "Ports": {},
                "SandboxKey": "/var/run/docker/netns/d80dfcd35589",
                "SecondaryIPAddresses": null,
                "SecondaryIPv6Addresses": null,
                "EndpointID": "41234855c20dd7890acb5e3a48217c14e61a1e3ab876d01f79ed03b88d543b88",
                "Gateway": "172.17.0.1",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "IPAddress": "172.17.0.2",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "MacAddress": "02:42:ac:11:00:02",
                "Networks": {
                    "bridge": {
                        "IPAMConfig": null,
                        "Links": null,
                        "Aliases": null,
                        "NetworkID": "5702770d4ed5c8618623571e5e7d4fa386b63c152a28bc01c40830bb8e389d21",
                        "EndpointID": "41234855c20dd7890acb5e3a48217c14e61a1e3ab876d01f79ed03b88d543b88",
                        "Gateway": "172.17.0.1",
                        "IPAddress": "172.17.0.2",
                        "IPPrefixLen": 16,
                        "IPv6Gateway": "",
                        "GlobalIPv6Address": "",
                        "GlobalIPv6PrefixLen": 0,
                        "MacAddress": "02:42:ac:11:00:02",
                        "DriverOpts": null
                    }
                }
            }
        }
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    进入当前正在运行的容器
    docker exec -it 容器id bashShell			# 进入容器后开启一个新的终端,可以再里面操作
    docker attach 容器id						# 进入容器正在执行的终端,不会开启新的进程
    
    -it    # 表示使用交互模式
    
    下面是例子
    [root@localhost ~]# docker exec -it 3926294a2cca /bin/bash
    [root@3926294a2cca /]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    从容器内拷贝文件到主机上
    docker cp 容器id:容器内路径 目的主机路径
    
    下面是例子: 首先进入到容器home文件夹建立一个文件,随后退出到本机,再利用docker复制命令把容器的文件复制到本机的home里面来
    [root@localhost ~]# docker exec -it 3926294a2cca /bin/bash
    [root@3926294a2cca /]# cd home
    [root@3926294a2cca home]# 
    [root@3926294a2cca home]# touch chenxiansheng222.java 
    [root@3926294a2cca home]# ls
    chenxiansheng222.java
    [root@3926294a2cca home]# exit
    exit
    [root@localhost ~]# docker ps -a
    CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                        PORTS     NAMES
    3926294a2cca   centos    "/bin/sh -c 'while t…"   35 minutes ago   Up 35 minutes                           fervent_torvalds
    47d1e769d463   centos    "/bin/sh -c 'while t…"   36 minutes ago   Exited (137) 35 minutes ago             great_wing
    00faae8b4bf2   centos    "/bin/bash"              18 hours ago     Exited (0) 18 hours ago                 suspicious_meninsky
    1581a1d0cf0a   centos    "/bin/bash"              18 hours ago     Exited (0) 18 hours ago                 serene_bouman
    
    
    # 使用复制命令将容器的文件复制到本机的linux上来
    [root@localhost ~]# docker cp 3926294a2cca:/home/chenxiansheng222.java /home 
    [root@3926294a2cca home]# exit
    exit
    [root@localhost /]# cd home/
    [root@localhost home]# ls
    chenmaolin  chenxiansheng222.java				# 可以看到文件已经正确复制到本机上了
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    实际应用

    docker 安装 Nginx

    1、 下载nginx 镜像
    2、 启动nginx
    3、测试
    docker run -d --name nginx01 -p 3344:80 nginx

    • -d # 设置后台运行
    • –name nginx01 # 给要启动的nginx一个名字,取名为nginx01
    • -p 3344:80 # 3344指的是linux的端口号,80指的是nginx容器的默认端口,将容器的
    # 下载nginx 镜像
    [root@localhost ~]# docker pull nginx
    Using default tag: latest
    latest: Pulling from library/nginx
    a2abf6c4d29d: Pull complete 
    a9edb18cadd1: Pull complete 
    589b7251471a: Pull complete 
    186b1aaa4aa6: Pull complete 
    b4df32aa5a72: Pull complete 
    a0bcbecc962e: Pull complete 
    Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
    Status: Downloaded newer image for nginx:latest
    docker.io/library/nginx:latest
    [root@localhost ~]# docker images
    REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
    nginx        latest    605c77e624dd   4 months ago   141MB
    centos       latest    5d0da3dc9764   8 months ago   231MB
    
    # 运行nginx镜像,参数说明:
    
     - -d  					# 设置后台运行
     - --name nginx01		# 给要启动的nginx一个名字,取名为nginx01	
     - -p 3344:80			# 3344指的是linux的端口号,80指的是nginx容器的默认端口,将容器的端口映射到linux端口
     - nginx 				#指的是容器名称REPOSITORY   
    [root@localhost ~]# docker run -d --name nginx01 -p 3344:80 nginx
    e87309bccecb4163d75b0cf6d87ebadc330e64b6de14e7c31fd0a76da19f23d8
    
    # 查看运行的nginx ,可以看到容器运行成功
    [root@localhost ~]# docker ps
    CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES
    e87309bccecb   nginx     "/docker-entrypoint.…"   26 seconds ago   Up 23 seconds   0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01
    
    # 测试nginx,可以看到 welcome to nginx ,测试成功
    [root@localhost ~]# curl localhost:3344
    <!DOCTYPE html>
    
    
    Welcome to nginx!<<span class="token operator">/</span>title>
    <style>
    html <span class="token punctuation">{<!-- --></span> color-scheme: light dark<span class="token punctuation">;</span> <span class="token punctuation">}</span>
    body <span class="token punctuation">{<!-- --></span> width: 35em<span class="token punctuation">;</span> margin: 0 auto<span class="token punctuation">;</span>
    font-family: Tahoma<span class="token punctuation">,</span> Verdana<span class="token punctuation">,</span> Arial<span class="token punctuation">,</span> sans-serif<span class="token punctuation">;</span> <span class="token punctuation">}</span>
    <<span class="token operator">/</span>style>
    <<span class="token operator">/</span>head>
    <body>
    <h1>Welcome to nginx!<<span class="token operator">/</span>h1>
    <p><span class="token keyword">If</span> you see this page<span class="token punctuation">,</span> the nginx web server is successfully installed and
    working<span class="token punctuation">.</span> Further configuration is required<span class="token punctuation">.</span><<span class="token operator">/</span>p>
    
    <p><span class="token keyword">For</span> online documentation and support please refer to
    <a href=<span class="token string">"http://nginx.org/"</span>>nginx<span class="token punctuation">.</span>org<<span class="token operator">/</span>a><span class="token punctuation">.</span><br/>
    Commercial support is available at
    <a href=<span class="token string">"http://nginx.com/"</span>>nginx<span class="token punctuation">.</span>com<<span class="token operator">/</span>a><span class="token punctuation">.</span><<span class="token operator">/</span>p>
    
    <p><em>Thank you <span class="token keyword">for</span> <span class="token keyword">using</span> nginx<span class="token punctuation">.</span><<span class="token operator">/</span>em><<span class="token operator">/</span>p>
    <<span class="token operator">/</span>body>
    <<span class="token operator">/</span>html>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li></ul></pre> 
    <p>还可以直接访问linux 的服务器加上上面启动的端口测试nginx是否运行成功<br> <strong>这个192.168.239.128 是我的linux服务器的地址</strong><br> <img src="https://1000bd.com/contentImg/2023/11/04/155325300.png" alt="在这里插入图片描述"></p> 
    <pre data-index="21" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 进入到nginx容器查看</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker exec -it e87309bccecb /bin/bash</span>
    root@e87309bccecb:<span class="token operator">/</span><span class="token comment"># ls</span>
    bin   dev		   docker-entrypoint<span class="token punctuation">.</span>sh  home  lib64  mnt  proc  run   srv  tmp  <span class="token keyword">var</span>
    boot  docker-entrypoint<span class="token punctuation">.</span>d  etc			 lib   media  opt  root  sbin  sys  usr
    root@e87309bccecb:<span class="token operator">/</span><span class="token comment"># whereis nginx</span>
    nginx: <span class="token operator">/</span>usr/sbin/nginx <span class="token operator">/</span>usr/lib/nginx <span class="token operator">/</span>etc/nginx <span class="token operator">/</span>usr/share/nginx
    root@e87309bccecb:<span class="token operator">/</span><span class="token comment"># </span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li></ul></pre> 
    <h5><a id="docker_tomcat_685"></a>docker 安装tomcat</h5> 
    <pre data-index="22" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">docker  run <span class="token operator">-</span>it  <span class="token operator">--</span><span class="token function">rm</span>  tomcat:9<span class="token punctuation">.</span>0			
    
     <span class="token operator">-</span> <span class="token operator">-</span><span class="token function">rm</span>  指的是运行容器停止后,在docker <span class="token function">ps</span> <span class="token operator">-</span>a 下会搜不到历史运行的该容器的id<span class="token punctuation">,</span>也就是停止容器后,会立马把该容器的历史删除掉
    
    <span class="token comment"># 首先下载tomcat镜像</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker pull tomcat:9.0</span>
    9<span class="token punctuation">.</span>0: Pulling <span class="token keyword">from</span> library/tomcat
    0e29546d541c: Pull complete 
    9b829c73b52b: Pull complete 
    cb5b7ae36172: Pull complete 
    6494e4811622: Pull complete 
    668f6fcc5fa5: Pull complete 
    dc120c3e0290: Pull complete 
    8f7c0eebb7b1: Pull complete 
    77b694f83996: Pull complete 
    7662046c36cb: Pull complete 
    b93639122cb4: Pull complete 
    Digest: sha256:cd96d4f7d3f5fc4d3bc1622ec678207087b8215d55021a607ecaefba80b403ea
    Status: Downloaded newer image <span class="token keyword">for</span> tomcat:9<span class="token punctuation">.</span>0
    docker<span class="token punctuation">.</span>io/library/tomcat:9<span class="token punctuation">.</span>0
    
    <span class="token comment"># 运行tomcat ,可以正常看到输出的tomcat的启动日志</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker run -it --rm tomcat:9.0</span>
    <span class="token keyword">Using</span> CATALINA_BASE:   <span class="token operator">/</span>usr/local/tomcat
    <span class="token keyword">Using</span> CATALINA_HOME:   <span class="token operator">/</span>usr/local/tomcat
    <span class="token keyword">Using</span> CATALINA_TMPDIR: <span class="token operator">/</span>usr/local/tomcat/temp
    <span class="token keyword">Using</span> JRE_HOME:        <span class="token operator">/</span>usr/local/openjdk-11
    <span class="token keyword">Using</span> CLASSPATH:       <span class="token operator">/</span>usr/local/tomcat/bin/bootstrap<span class="token punctuation">.</span>jar:<span class="token operator">/</span>usr/local/tomcat/bin/tomcat-juli<span class="token punctuation">.</span>jar
    <span class="token keyword">Using</span> CATALINA_OPTS:   
    NOTE: Picked up JDK_JAVA_OPTIONS:  <span class="token operator">--</span><span class="token function">add-opens</span>=java<span class="token punctuation">.</span>base/java<span class="token punctuation">.</span>lang=ALL-UNNAMED <span class="token operator">--</span><span class="token function">add-opens</span>=java<span class="token punctuation">.</span>base/java<span class="token punctuation">.</span>io=ALL-UNNAMED <span class="token operator">--</span><span class="token function">add-opens</span>=java<span class="token punctuation">.</span>base/java<span class="token punctuation">.</span>util=ALL-UNNAMED <span class="token operator">--</span><span class="token function">add-opens</span>=java<span class="token punctuation">.</span>base/java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>concurrent=ALL-UNNAMED <span class="token operator">--</span><span class="token function">add-opens</span>=java<span class="token punctuation">.</span>rmi/sun<span class="token punctuation">.</span>rmi<span class="token punctuation">.</span>transport=ALL-UNNAMED
    22-May-2022 13:44:17<span class="token punctuation">.</span>732 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Server version name:   Apache Tomcat/9<span class="token punctuation">.</span>0<span class="token punctuation">.</span>56
    22-May-2022 13:44:17<span class="token punctuation">.</span>736 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Server built:          Dec 2 2021 14:30:07 UTC
    22-May-2022 13:44:17<span class="token punctuation">.</span>743 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log CATALINA_HOME:         <span class="token operator">/</span>usr/local/tomcat
    22-May-2022 13:44:17<span class="token punctuation">.</span>817 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Djava<span class="token punctuation">.</span>util<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>config<span class="token punctuation">.</span>file=<span class="token operator">/</span>usr/local/tomcat/conf/logging<span class="token punctuation">.</span>properties
    22-May-2022 13:44:17<span class="token punctuation">.</span>818 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Djava<span class="token punctuation">.</span>util<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>manager=org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>juli<span class="token punctuation">.</span>ClassLoaderLogManager
    22-May-2022 13:44:17<span class="token punctuation">.</span>818 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Djdk<span class="token punctuation">.</span>tls<span class="token punctuation">.</span>ephemeralDHKeySize=2048
    22-May-2022 13:44:17<span class="token punctuation">.</span>819 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Djava<span class="token punctuation">.</span>protocol<span class="token punctuation">.</span>handler<span class="token punctuation">.</span>pkgs=org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>webresources
    22-May-2022 13:44:17<span class="token punctuation">.</span>819 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Dorg<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>security<span class="token punctuation">.</span>SecurityListener<span class="token punctuation">.</span>UMASK=0027
    22-May-2022 13:44:17<span class="token punctuation">.</span>819 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Dignore<span class="token punctuation">.</span>endorsed<span class="token punctuation">.</span>dirs=
    22-May-2022 13:44:17<span class="token punctuation">.</span>819 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Dcatalina<span class="token punctuation">.</span>base=<span class="token operator">/</span>usr/local/tomcat
    22-May-2022 13:44:17<span class="token punctuation">.</span>819 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Dcatalina<span class="token punctuation">.</span>home=<span class="token operator">/</span>usr/local/tomcat
    22-May-2022 13:44:17<span class="token punctuation">.</span>820 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>VersionLoggerListener<span class="token punctuation">.</span>log Command line argument: <span class="token operator">-</span>Djava<span class="token punctuation">.</span>io<span class="token punctuation">.</span>tmpdir=<span class="token operator">/</span>usr/local/tomcat/temp
    22-May-2022 13:44:17<span class="token punctuation">.</span>866 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>core<span class="token punctuation">.</span>AprLifecycleListener<span class="token punctuation">.</span>lifecycleEvent Loaded Apache Tomcat Native library <span class="token punctuation">[</span>1<span class="token punctuation">.</span>2<span class="token punctuation">.</span>31<span class="token punctuation">]</span> <span class="token keyword">using</span> APR version <span class="token punctuation">[</span>1<span class="token punctuation">.</span>7<span class="token punctuation">.</span>0<span class="token punctuation">]</span><span class="token punctuation">.</span>
    22-May-2022 13:44:17<span class="token punctuation">.</span>866 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>core<span class="token punctuation">.</span>AprLifecycleListener<span class="token punctuation">.</span>lifecycleEvent APR capabilities: IPv6 <span class="token namespace">[true]</span><span class="token punctuation">,</span> sendfile <span class="token namespace">[true]</span><span class="token punctuation">,</span> accept filters <span class="token namespace">[false]</span><span class="token punctuation">,</span> random <span class="token namespace">[true]</span><span class="token punctuation">,</span> UDS <span class="token namespace">[true]</span><span class="token punctuation">.</span>
    22-May-2022 13:44:17<span class="token punctuation">.</span>866 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>core<span class="token punctuation">.</span>AprLifecycleListener<span class="token punctuation">.</span>lifecycleEvent APR/OpenSSL configuration: useAprConnector <span class="token namespace">[false]</span><span class="token punctuation">,</span> useOpenSSL <span class="token namespace">[true]</span>
    22-May-2022 13:44:17<span class="token punctuation">.</span>889 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>core<span class="token punctuation">.</span>AprLifecycleListener<span class="token punctuation">.</span>initializeSSL OpenSSL successfully initialized <span class="token namespace">[OpenSSL 1.1.1k  25 Mar 2021]</span>
    22-May-2022 13:44:19<span class="token punctuation">.</span>883 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>coyote<span class="token punctuation">.</span>AbstractProtocol<span class="token punctuation">.</span>init Initializing ProtocolHandler <span class="token punctuation">[</span><span class="token string">"http-nio-8080"</span><span class="token punctuation">]</span>
    22-May-2022 13:44:20<span class="token punctuation">.</span>074 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>Catalina<span class="token punctuation">.</span>load Server initialization in <span class="token punctuation">[</span>3403<span class="token punctuation">]</span> milliseconds
    22-May-2022 13:44:20<span class="token punctuation">.</span>392 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>core<span class="token punctuation">.</span>StandardService<span class="token punctuation">.</span>startInternal Starting service <span class="token namespace">[Catalina]</span>
    22-May-2022 13:44:20<span class="token punctuation">.</span>402 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>core<span class="token punctuation">.</span>StandardEngine<span class="token punctuation">.</span>startInternal Starting Servlet engine: <span class="token namespace">[Apache Tomcat/9.0.56]</span>
    22-May-2022 13:44:20<span class="token punctuation">.</span>446 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>coyote<span class="token punctuation">.</span>AbstractProtocol<span class="token punctuation">.</span><span class="token function">start</span> Starting ProtocolHandler <span class="token punctuation">[</span><span class="token string">"http-nio-8080"</span><span class="token punctuation">]</span>
    22-May-2022 13:44:20<span class="token punctuation">.</span>516 INFO <span class="token namespace">[main]</span> org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>catalina<span class="token punctuation">.</span>startup<span class="token punctuation">.</span>Catalina<span class="token punctuation">.</span><span class="token function">start</span> Server startup in <span class="token punctuation">[</span>441<span class="token punctuation">]</span> milliseconds
    
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li></ul></pre> 
    <p>这里可以看到,tomcat容器启动完后,容器也被删除了,这就是–rm 命令的作用<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325431.png" alt="在这里插入图片描述"></p> 
    <pre data-index="23" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 继续测试,利用linux的地址,进行访问tomcat(将tomcat8080的默认端口映射到本机的3355端口)</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker run -d -p 3355:8080 --name tomcat01 tomcat </span>
    77a49b3e9292c5e9bd7acd8bf9f85db7e07005493819fd6773f8158c02c1e670
    
    <span class="token comment"># 测试访问linux:3355地址,会发现报404,原因是因为该tomcat是阉割版,webapps文件是空的</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># curl localhost:3355</span>
    <<span class="token operator">!</span>doctype html><html lang=<span class="token string">"en"</span>><head><title>HTTP Status 404 – Not Found<<span class="token operator">/</span>title><style <span class="token function">type</span>=<span class="token string">"text/css"</span>>body <span class="token punctuation">{<!-- --></span>font-family:Tahoma<span class="token punctuation">,</span>Arial<span class="token punctuation">,</span>sans-serif<span class="token punctuation">;</span><span class="token punctuation">}</span> h1<span class="token punctuation">,</span> h2<span class="token punctuation">,</span> h3<span class="token punctuation">,</span> b <span class="token punctuation">{<!-- --></span>color:white<span class="token punctuation">;</span>background-color:<span class="token comment">#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/10.0.14</h3></body></html>[root@localhost ~]# ^C</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li></ul></pre> 
    <p>利用linux地址:3355访问测试<img src="https://1000bd.com/contentImg/2023/11/04/155325359.png" alt="在这里插入图片描述"></p> 
    <p>那为什么使用linux地址:3355 没有访问tomcat成功呢,明明容器已经正常启动了。<br> 原因是因为该tomcat是阉割版本的,对应的webapps文件夹下是空的</p> 
    <pre data-index="24" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 进入到tomcat容器里,ls查看目录</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker exec -it 77a49b3e9292 /bin/bash</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat<span class="token comment"># ls</span>
    BUILDING<span class="token punctuation">.</span>txt	 LICENSE  README<span class="token punctuation">.</span>md	 RUNNING<span class="token punctuation">.</span>txt  conf  logs	    temp     webapps<span class="token punctuation">.</span>dist
    CONTRIBUTING<span class="token punctuation">.</span>md  NOTICE   RELEASE-NOTES  bin	      lib   native-jni-lib  webapps  work
    
    <span class="token comment"># 进入到webapps目录,发现是空目录</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat<span class="token comment"># cd webapps</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat/webapps<span class="token comment"># ls</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat/webapps<span class="token comment"># </span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li></ul></pre> 
    <p>但是,可以看到,虽然该阉割版的tomcat的webapps目录是空的,但是对应的webapps.dist 目录却是有内容的,而里面的内容刚好是webapps文件所需要的</p> 
    <pre data-index="25" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat<span class="token comment"># cd webapps.dist/</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat/webapps<span class="token punctuation">.</span>dist<span class="token comment"># ll		# 由于是阉割版本,所有ll命令都没有</span>
    bash: ll: command not found
    
    <span class="token comment"># 可以看到,webapps.dist 目录下的文件都是webapps所需要的,把它复制到webapps 目录下</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat/webapps<span class="token punctuation">.</span>dist<span class="token comment"># ls</span>
    ROOT  docs  examples  host-manager  manager					
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li></ul></pre> 
    <p>使用cp命令,将webapps.dist 目录下的文件拷贝到webapps 目录下,使用本机地址加3355端口号就可以成功访问tomcat了</p> 
    <pre data-index="26" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat<span class="token comment"># cp -r  webapps.dist/* webapps</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat<span class="token comment"># cd webapps</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat/webapps<span class="token comment"># ls</span>
    ROOT  docs  examples  host-manager  manager				<span class="token comment"># webapps文件有内容了</span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
    <p>重新使用liunx地址+3355 (前面启动tomcat容器的时候指定了映射到linux的3355端口)端口号访问:<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325020.png" alt="在这里插入图片描述"><br> 熟悉的tomcat页面,访问成功!!!</p> 
    <h3><a name="t10"></a><a id="docker_799"></a>docker图形化安装</h3> 
    <h5><a id="portainer_800"></a>安装<a href="https://so.csdn.net/so/search?q=portainer&spm=1001.2101.3001.7020" target="_blank" class="hl hl-1" data-report-view="{"spm":"1001.2101.3001.7020","dest":"https://so.csdn.net/so/search?q=portainer&spm=1001.2101.3001.7020","extra":"{\"searchword\":\"portainer\"}"}" data-report-click="{"spm":"1001.2101.3001.7020","dest":"https://so.csdn.net/so/search?q=portainer&spm=1001.2101.3001.7020","extra":"{\"searchword\":\"portainer\"}"}" data-tit="portainer" data-pretit="portainer">portainer</a></h5> 
    <blockquote> 
     <p>portainer:Docker图形化界面管理工具! 提供一个后台面板供我们操作</p> 
    </blockquote> 
    <p>使用下面的命令安装portainer,并把端口映射到linux的8088端口(这样就可以用linux地址+端口号访问了)</p> 
    <blockquote> 
     <p>docker run -d -p 8088:9000 <br> –restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer</p> 
    </blockquote> 
    <p>安装成功<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325298.png" alt="在这里插入图片描述"><br> 设置账号:root 密码:rootroot</p> 
    <p>登陆后,选择连接本地,可以查看已有的镜像(不是重点,一般不用,了解即可):<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325655.png" alt="在这里插入图片描述"></p> 
    <h3><a name="t11"></a><a id="_815"></a>镜像的分层的含义(待补充)</h3> 
    <h5><a id="commit_819"></a>commit镜像</h5> 
    <blockquote> 
     <p>docker commit</p> 
    </blockquote> 
    <pre data-index="27" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">提交镜像命令:docker commit <span class="token operator">-</span>a=<span class="token string">"chenxiansheng"</span> <span class="token operator">-</span>m=<span class="token string">"add webapps app"</span> 77a49b3e9292 chentomcat:1<span class="token punctuation">.</span>0
    参数说明:
     <span class="token operator">-</span> <span class="token operator">-</span>a=<span class="token string">"chenxiansheng"</span>				<span class="token comment"># 提交的人的标识</span>
     <span class="token operator">-</span> <span class="token operator">-</span>m=<span class="token string">"add webapps app"</span>    			<span class="token comment">#提交的描述</span>
     <span class="token operator">-</span>  77a49b3e9292 					<span class="token comment">#容器id</span>
     <span class="token operator">-</span> chentomcat:1<span class="token punctuation">.</span>0					<span class="token comment">#设定镜像名称,并设定版本为1.0</span>
    
    步骤:
    <span class="token comment"># 1、首先利用上面下载好的tomcat镜像,启动一个tomcat容器</span>
    <span class="token comment"># 2、然而这个默认的tomcat是没有webapps应用的,镜像的原因,官方的镜像默认webapps下面是没有文件的</span>
    <span class="token comment"># 3、把基本文件拷贝进webapps里面</span>
    <span class="token comment"># 4、将上面操作过的容器通过commit 提交为一个新的镜像,以后就可以使用自己的镜像,可以直接访问tomcat页面成功。</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li></ul></pre> 
    <blockquote> 
     <p>上面说的步骤,有不懂的,可以查看上面的docker 安装tomcat ,由于官方的tomcat是阉割版的,访问不了tomcat页面(原因是webapps目录没有文件),我们这里就把他优化一下,就是把webapps目录的文件补充完整。</p> 
    </blockquote> 
    <pre data-index="28" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 使用cp命令,将webapps.dist 目录下的文件拷贝到webapps 目录下,使用本机地址加3355端口号就可以成功访问tomcat了</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat<span class="token comment"># cp -r  webapps.dist/* webapps</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat<span class="token comment"># cd webapps</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat/webapps<span class="token comment"># ls</span>
    ROOT  docs  examples  host-manager  manager				<span class="token comment"># webapps文件有内容了</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
    <p>测试一下<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325483.png" alt="在这里插入图片描述"><br> 测试没有问题,现在把这个运行的容器,提交成我们自己的镜像。以后运行就用我们自己的tomcat镜像,就不需要再做一次将webapps.dict 目录的文件拷贝到webapps目录下的操作后,才能查看tomcat页面了。</p> 
    <pre data-index="29" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 从刚刚启动的容器中退出来</span>
    root@77a49b3e9292:<span class="token operator">/</span>usr/local/tomcat/webapps<span class="token comment"># exit</span>
    <span class="token keyword">exit</span>
    
    <span class="token comment"># 使用提交镜像命令</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker commit -a="chenxiansheng" -m="add webapps app" 77a49b3e9292 chentomcat:1.0</span>
    sha256:8c3fc729e0f1c139d2b7b1cbe7acb2c3f12cb5c8e3cdf307dc5813fb8258c613
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre> 
    <blockquote> 
     <p>可以看到我们已经生成了自己的镜像了 chentomcat</p> 
    </blockquote> 
    <pre data-index="30" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker images</span>
    REPOSITORY            TAG       IMAGE ID       CREATED              SIZE
    chentomcat            1<span class="token punctuation">.</span>0       8c3fc729e0f1   About a minute ago   684MB
    nginx                 latest    605c77e624dd   4 months ago         141MB
    tomcat                9<span class="token punctuation">.</span>0       b8e65a4d736d   5 months ago         680MB
    tomcat                latest    fb5657adc892   5 months ago         680MB
    centos                latest    5d0da3dc9764   8 months ago         231MB
    portainer/portainer   latest    580c0e4e98b0   14 months ago        79<span class="token punctuation">.</span>1MB
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre> 
    <h3><a name="t12"></a><a id="_875"></a>容器数据卷</h3> 
    <h5><a id="_v__876"></a>通过添加 -v 参数实现数据卷功能</h5> 
    <blockquote> 
     <p>为了将容器的数据进行持久化保存的操作。防止删掉容器后,容器内的数据也没有。<br> 作用:挂载宿主机的一个目录<br> 这里把容器想成一个单独的系统,或者说电脑,而你的宿主机目录是一个U盘,挂载后,你往宿主机该目录里放文件,那么通过容器里对应目录便可以访问到此文件,不需要重新生成容器就可以在“容器外部”添加和修改某些文件,如我用Mythri工具检测智能合约漏洞,采用docker容器如下命令:docker run -v $(pwd):/tmp mythril/myth analyze /tmp/test.sol,将宿主机当前目录挂载到容器的tmp目录,则在容器中操作时tmp目录就是当前的目录,在当期目录中新建智能合约或者改变旧的合约如test.sol的内容,再通过analyze命令检测合约即可,既不用重新生成容器,也不需要知道容器的绝对路径从而将新合约复制进去,只需要复制到当前目录即可。</p> 
    </blockquote> 
    <pre data-index="31" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">命令:docker run <span class="token operator">-</span>it <span class="token operator">-</span>v 主机目录:容器目录 容器名称
    
    <span class="token comment"># 首先确认下本机linux目录下是没有其他目录的</span>
    <span class="token namespace">[root@localhost /]</span><span class="token comment"># cd home/</span>
    <span class="token namespace">[root@localhost home]</span><span class="token comment">#</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
    <blockquote> 
     <p>1、我们首先在本机的home目录下,新建一个名叫ceshi的目录,随后我们将主机的home/ceshi 目录挂载到容器的home目录下。到时候这两个目录任一一个有改动,另外一个目录也能同步改动</p> 
    </blockquote> 
    <pre data-index="32" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 启动centos容器,并且将主机的home/ceshi目录挂载到容器的home目录,并且成功进入到容器里面</span>
    <span class="token namespace">[root@localhost home]</span><span class="token comment"># docker run -it -v /home/ceshi:/home centos</span>
    <span class="token namespace">[root@9df6ac86d312 /]</span><span class="token comment"># </span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
    <blockquote> 
     <p>2、进一步查看已经开启数据卷的容器的进程信息,使用inspect命令</p> 
    </blockquote> 
    <pre data-index="33" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost ceshi]</span><span class="token comment"># docker inspect 9df6ac86d312</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
    <p><img src="https://1000bd.com/contentImg/2023/11/04/155325728.png" alt="在这里插入图片描述"></p> 
    <blockquote> 
     <p>3、新开一个会话,进入到linux的home/ceshi目录下,可以看到,ceshi目录是没有任何文件的</p> 
    </blockquote> 
    <pre data-index="34" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost home]</span><span class="token comment"># cd ceshi/</span>
    <span class="token namespace">[root@localhost ceshi]</span><span class="token comment"># ls</span>
    <span class="token namespace">[root@localhost ceshi]</span><span class="token comment"># </span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
    <blockquote> 
     <p>4、开始测试,往容器的home目录添加文件,新建test.java文件</p> 
    </blockquote> 
    <pre data-index="35" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@9df6ac86d312 /]</span><span class="token comment"># cd home/</span>
    <span class="token namespace">[root@9df6ac86d312 home]</span><span class="token comment"># touch test.java</span>
    <span class="token namespace">[root@9df6ac86d312 home]</span><span class="token comment"># ls</span>
    test<span class="token punctuation">.</span>java
    <span class="token namespace">[root@9df6ac86d312 home]</span><span class="token comment"># </span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li></ul></pre> 
    <blockquote> 
     <p>5、去linux的home/ceshi目录查看,是否有新建的test.java文件</p> 
    </blockquote> 
    <pre data-index="36" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost ceshi]</span><span class="token comment"># ls</span>
    test<span class="token punctuation">.</span>java
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
    <p>结果:可以看到,主机目录已经成功挂载到容器的目录里。容器里面的home目录有什么变动,linux下的home/ceshi目录也会跟着同步。</p> 
    <p>下面我们来变动linux中home/ceshi/test.java文件,那容器home目录下的test.java文件会不会也会跟着变动呢?</p> 
    <blockquote> 
     <p>1、这里,我往linux的test.java文件,输入了一行字,:wq 保存退出。</p> 
    </blockquote> 
    <pre data-index="37" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost ceshi]</span><span class="token comment"># vi test.java</span>
    <span class="token namespace">[root@localhost ceshi]</span><span class="token comment"># cat test.java </span>
    hello<span class="token punctuation">,</span>chenxiansheng
    <span class="token namespace">[root@localhost ceshi]</span><span class="token comment">#</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre> 
    <blockquote> 
     <p>2、现在去查看容器的test.java文件,可以看到,也是同步成功的</p> 
    </blockquote> 
    <pre data-index="38" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@9df6ac86d312 home]</span><span class="token comment"># cat test.java </span>
    hello<span class="token punctuation">,</span>chenxiansheng
    <span class="token namespace">[root@9df6ac86d312 home]</span><span class="token comment"># </span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre> 
    <p>根据上面我们得出结论。容器数据卷功能,是通过在启动容器时,加上-v 参数,写上要挂载的目录和绑定的目录,使得这两个不在同一个层面的目录有了双向绑定的功能,数据可以实现同步(就算是容器已经停止运行,双向绑定的作用依然有效)。</p> 
    <h5><a id="mysql_945"></a>安装mysql进行数据卷的实战测试</h5> 
    <pre data-index="39" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 下载mysql镜像</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker pull mysql:5.7</span>
    5<span class="token punctuation">.</span>7: Pulling <span class="token keyword">from</span> library/mysql
    72a69066d2fe: Pull complete 
    93619dbc5b36: Pull complete 
    99da31dd6142: Pull complete 
    626033c43d70: Pull complete 
    37d5d7efb64e: Pull complete 
    ac563158d721: Pull complete 
    d2ba16033dad: Pull complete 
    0ceb82207cd7: Pull complete 
    37f2405cae96: Pull complete 
    e2482e017e53: Pull complete 
    70deed891d42: Pull complete 
    Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
    Status: Downloaded newer image <span class="token keyword">for</span> mysql:5<span class="token punctuation">.</span>7
    docker<span class="token punctuation">.</span>io/library/mysql:5<span class="token punctuation">.</span>7
    <span class="token comment"># 查看镜像</span>
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker images</span>
    REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
    chentomcat            1<span class="token punctuation">.</span>0       8c3fc729e0f1   47 hours ago    684MB
    nginx                 latest    605c77e624dd   4 months ago    141MB
    tomcat                9<span class="token punctuation">.</span>0       b8e65a4d736d   5 months ago    680MB
    tomcat                latest    fb5657adc892   5 months ago    680MB
    mysql                 5<span class="token punctuation">.</span>7       c20987f18b13   5 months ago    448MB
    centos                latest    5d0da3dc9764   8 months ago    231MB
    portainer/portainer   latest    580c0e4e98b0   14 months ago   79<span class="token punctuation">.</span>1MB
    
    <span class="token comment"># 运行mysql容器。 </span>
    参数说明:
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker run -d -p 3310:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mysqlO1 mysql:5.7</span>
    6a2caa469f09e9ff2417d31634fb50a4624118d1724f236ca0962a62989bb2f8
    <span class="token namespace">[root@localhost ~]</span><span class="token comment"># </span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li></ul></pre> 
    <p>测试连接:<br> 这里我使用Navicat Premium工具连接测试<br> 192.168.239.128 是我的linux地址,可以看到,连接成功<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325352.png" alt="在这里插入图片描述"><br> 查看linux中的home/mysql文件夹:<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325435.png" alt="在这里插入图片描述"><br> 然后我们使用Navicat Premium 工具,在该mysql中新建test数据库:</p> 
    <p><img src="https://1000bd.com/contentImg/2023/11/04/155325143.png" alt="在这里插入图片描述"><br> 重新查看本机的home/mysql/data目录,可以看到,新增了test文件夹<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325144.png" alt="在这里插入图片描述"></p> 
    <blockquote> 
     <p>以上得出结论,我们是在容器的mysql新建了数据库,我们可以在linux上找到容器新建的test数据库,这两个文件夹实现了双向绑定。假如我们把容器删除了,数据也不会丢失,实现了数据的持久化功能。</p> 
    </blockquote> 
    <h5><a id="_998"></a>具名和匿名挂载</h5> 
    <h6><a id="docker_volume__999"></a>使用docker volume 查看数据卷的文件夹信息</h6> 
    <pre data-index="40" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">docker run <span class="token operator">-</span>d <span class="token operator">-</span>p <span class="token operator">--</span>name nginx01 <span class="token operator">-</span>v <span class="token operator">/</span>etc/nginx nginx
    <span class="token operator">-</span>P  随机指定端口
    
    <span class="token namespace">[root@localhost /]</span><span class="token comment"># docker run -d -P --name nginx02 -v /etc/nginx nginx</span>
    5035f960746ba9a373fdeeec59e837f77793465055ade7e46e49d11d3e820a6d
    
    <span class="token comment"># 使用docker volume 命令查看数据卷具体信息</span>
    <span class="token namespace">[root@localhost /]</span><span class="token comment"># docker volume --help</span>
    
    Usage:  docker volume COMMAND
    
    Manage volumes
    
    Commands:
      create      Create a volume
      inspect     Display detailed information on one or more volumes
      <span class="token function">ls</span>          List volumes
      prune       Remove all unused local volumes
      <span class="token function">rm</span>          Remove one or more volumes
    
    Run <span class="token string">'docker volume COMMAND --help'</span> <span class="token keyword">for</span> more information on a command<span class="token punctuation">.</span>
    
    <span class="token comment"># docker volume ls 命令列出该数据卷文件夹</span>
    <span class="token namespace">[root@localhost /]</span><span class="token comment"># docker volume ls</span>
    DRIVER    VOLUME NAME
    local     5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef
    local     d8bd26ce1c9d58e224d378446283b9166f53f1f3d9bb2ae3419d0dd67667cb20
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li></ul></pre> 
    <blockquote> 
     <p>因为上面的命令匿名挂载,也就是没有指定主机目录,所以它会自己生成一个目录,这里我都进入看过,它会把5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef 目录挂载到容器的/etc/nginx目录中。<br> 下面我们继续使用docker volume 命令,查看数据卷文件夹具体路径:</p> 
    </blockquote> 
    <pre data-index="41" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost home]</span><span class="token comment"># docker volume inspect 5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef</span>
    <span class="token punctuation">[</span>
        <span class="token punctuation">{<!-- --></span>
            <span class="token string">"CreatedAt"</span>: <span class="token string">"2022-05-25T21:55:11+08:00"</span><span class="token punctuation">,</span>
            <span class="token string">"Driver"</span>: <span class="token string">"local"</span><span class="token punctuation">,</span>
            <span class="token string">"Labels"</span>: null<span class="token punctuation">,</span>
            <span class="token string">"Mountpoint"</span>: <span class="token string">"/var/lib/docker/volumes/5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef/_data"</span><span class="token punctuation">,</span>
            <span class="token string">"Name"</span>: <span class="token string">"5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef"</span><span class="token punctuation">,</span>
            <span class="token string">"Options"</span>: null<span class="token punctuation">,</span>
            <span class="token string">"Scope"</span>: <span class="token string">"local"</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">]</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li></ul></pre> 
    <blockquote> 
     <p>从上面可以看出来,数据卷的文件夹放在/var/lib/docker/volumes/目录下,我们直接去到该目录下查看是否有nginx的文件</p> 
    </blockquote> 
    <pre data-index="42" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost home]</span><span class="token comment"># cd /var/lib/docker/volumes/5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef/</span>
    <span class="token namespace">[root@localhost 5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef]</span><span class="token comment"># ls</span>
    _data
    <span class="token namespace">[root@localhost 5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef]</span><span class="token comment"># cd _data/</span>
    <span class="token namespace">[root@localhost _data]</span><span class="token comment"># ls</span>
    conf<span class="token punctuation">.</span>d  fastcgi_params  mime<span class="token punctuation">.</span>types  modules  nginx<span class="token punctuation">.</span>conf  scgi_params  uwsgi_params
    <span class="token namespace">[root@localhost _data]</span><span class="token comment"># cat nginx.conf </span>
    
    user  nginx<span class="token punctuation">;</span>
    worker_processes  auto<span class="token punctuation">;</span>
    
    error_log  <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>log/nginx/error<span class="token punctuation">.</span>log notice<span class="token punctuation">;</span>
    pid        <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>run/nginx<span class="token punctuation">.</span>pid<span class="token punctuation">;</span>
    
    
    events <span class="token punctuation">{<!-- --></span>
        worker_connections  1024<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    
    http <span class="token punctuation">{<!-- --></span>
        include       <span class="token operator">/</span>etc/nginx/mime<span class="token punctuation">.</span>types<span class="token punctuation">;</span>
        default_type  application/octet-stream<span class="token punctuation">;</span>
    
        log_format  main  <span class="token string">'$remote_addr - $remote_user [$time_local] "$request" '</span>
                          <span class="token string">'$status $body_bytes_sent "$http_referer" '</span>
                          <span class="token string">'"$http_user_agent" "$http_x_forwarded_for"'</span><span class="token punctuation">;</span>
    
        access_log  <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>log/nginx/access<span class="token punctuation">.</span>log  main<span class="token punctuation">;</span>
    
        sendfile        on<span class="token punctuation">;</span>
        <span class="token comment">#tcp_nopush     on;</span>
    
        keepalive_timeout  65<span class="token punctuation">;</span>
    
        <span class="token comment">#gzip  on;</span>
    
        include <span class="token operator">/</span>etc/nginx/conf<span class="token punctuation">.</span>d/<span class="token operator">*</span><span class="token punctuation">.</span>conf<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token namespace">[root@localhost _data]</span><span class="token comment"># </span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li></ul></pre> 
    <blockquote> 
     <p>可以看到,nginx文件也是正确同步的。匿名挂载的缺点,就是生成的挂载目录的名字是不确定的,使我们不知道真正挂载的目录是哪一个,只能一个个找。</p> 
    </blockquote> 
    <h6><a id="_1095"></a>具名挂载</h6> 
    <p>同样,我们启动一个nginx容器,这一次我们指定主机目录juming (没有放在相对路径上,前面不需要加 “/”) ,此时再用docker volume 命令去查看目录的路径</p> 
    <pre data-index="43" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost /]</span><span class="token comment"># docker run -d -P --name nginx04 -v  juming:/etc/nginx nginx</span>
    d68b6d085d0304d43e205c5627c1fc790aea3391b09bf7b6304b2c71cafc8376
    <span class="token namespace">[root@localhost /]</span><span class="token comment"># docker volume ls</span>
    DRIVER    VOLUME NAME
    local     5935c0c061619752d5939c6c0567a588feacb171ec5bbe15be327e1952a32aef
    local     d8bd26ce1c9d58e224d378446283b9166f53f1f3d9bb2ae3419d0dd67667cb20
    local     juming
    
    <span class="token comment"># 使用 docker volume inspect 查看挂载目录的路径</span>
    <span class="token namespace">[root@localhost _data]</span><span class="token comment"># docker volume inspect juming</span>
    <span class="token punctuation">[</span>
        <span class="token punctuation">{<!-- --></span>
            <span class="token string">"CreatedAt"</span>: <span class="token string">"2022-05-25T22:29:57+08:00"</span><span class="token punctuation">,</span>
            <span class="token string">"Driver"</span>: <span class="token string">"local"</span><span class="token punctuation">,</span>
            <span class="token string">"Labels"</span>: null<span class="token punctuation">,</span>
            <span class="token string">"Mountpoint"</span>: <span class="token string">"/var/lib/docker/volumes/juming/_data"</span><span class="token punctuation">,</span>
            <span class="token string">"Name"</span>: <span class="token string">"juming"</span><span class="token punctuation">,</span>
            <span class="token string">"Options"</span>: null<span class="token punctuation">,</span>
            <span class="token string">"Scope"</span>: <span class="token string">"local"</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">]</span>
    
    
    <span class="token comment"># 进入到该挂载目录的_data目录,可以看到nginx.conf  也是存在的,说明具名挂载也是成功的</span>
    <span class="token namespace">[root@localhost /]</span><span class="token comment"># cd var/lib/docker/volumes/juming/_data/</span>
    <span class="token namespace">[root@localhost _data]</span><span class="token comment"># ls</span>
    conf<span class="token punctuation">.</span>d  fastcgi_params  mime<span class="token punctuation">.</span>types  modules  nginx<span class="token punctuation">.</span>conf  scgi_params  uwsgi_params
    <span class="token namespace">[root@localhost _data]</span><span class="token comment"># cat nginx.conf </span>
    
    user  nginx<span class="token punctuation">;</span>
    worker_processes  auto<span class="token punctuation">;</span>
    
    error_log  <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>log/nginx/error<span class="token punctuation">.</span>log notice<span class="token punctuation">;</span>
    pid        <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>run/nginx<span class="token punctuation">.</span>pid<span class="token punctuation">;</span>
    
    
    events <span class="token punctuation">{<!-- --></span>
        worker_connections  1024<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    
    http <span class="token punctuation">{<!-- --></span>
        include       <span class="token operator">/</span>etc/nginx/mime<span class="token punctuation">.</span>types<span class="token punctuation">;</span>
        default_type  application/octet-stream<span class="token punctuation">;</span>
    
        log_format  main  <span class="token string">'$remote_addr - $remote_user [$time_local] "$request" '</span>
                          <span class="token string">'$status $body_bytes_sent "$http_referer" '</span>
                          <span class="token string">'"$http_user_agent" "$http_x_forwarded_for"'</span><span class="token punctuation">;</span>
    
        access_log  <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>log/nginx/access<span class="token punctuation">.</span>log  main<span class="token punctuation">;</span>
    
        sendfile        on<span class="token punctuation">;</span>
        <span class="token comment">#tcp_nopush     on;</span>
    
        keepalive_timeout  65<span class="token punctuation">;</span>
    
        <span class="token comment">#gzip  on;</span>
    
        include <span class="token operator">/</span>etc/nginx/conf<span class="token punctuation">.</span>d/<span class="token operator">*</span><span class="token punctuation">.</span>conf<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token namespace">[root@localhost _data]</span><span class="token comment"># </span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li></ul></pre> 
    <blockquote> 
     <p>从上面的匿名挂载和具名挂载得出结论,<br> 不同点: 匿名挂载就是挂载的时候不主动指定要挂载的主机目录,此时会自动生成一个挂载目录,但是具体叫什么名字我们不清楚,只能使用 ”docker inspect 容器id “命令,从进程信息的mounts找出挂载的本机目录名称。 具名挂载就是在挂载的时候手动指定一个要挂载的目录,此时我们 ”docker volume ls “命令就能很轻松找到对应的主机目录。<br> 相同点:具名挂载和匿名挂载的主机目录都是存放在"/var/lib/docker/volumes/"路径上的</p> 
    </blockquote> 
    <p>拓展:</p> 
    <pre data-index="44" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 通过 -v 容器内路径:ro  /rw 改变读写权限</span>
    ro:				<span class="token comment"># 只读</span>
    rw:				<span class="token comment"># 可读可写</span>
     docker run <span class="token operator">-</span>d <span class="token operator">-</span>P <span class="token operator">--</span>name nginx03 <span class="token operator">-</span>v  <span class="token operator">/</span>home/juming:<span class="token operator">/</span>etc/nginx:ro nginx
     docker run <span class="token operator">-</span>d <span class="token operator">-</span>P <span class="token operator">--</span>name nginx03 <span class="token operator">-</span>v  <span class="token operator">/</span>home/juming:<span class="token operator">/</span>etc/nginx:rw nginx
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
    <blockquote> 
     <p>#ro 只要看到ro 就说明这个路径只能通过宿主机来操作,容器内部无法操作!(测试:看下面两张图片)</p> 
    </blockquote> 
    <p>往主机添加test.java文件(图1),可以看到容器也有test.java文件(图2),但是往容器添加test2.java文件,却报只有只读权限(图2)。<br> 图1<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325159.png" alt="图1"></p> 
    <p>图2 <br> <img src="https://1000bd.com/contentImg/2023/11/04/155324928.png" alt="图2"></p> 
    <h5><a id="Dockerfile_1186"></a>初识Dockerfile</h5> 
    <h6><a id="dockerfiledocker_build_1187"></a>构建dockerfile命令:docker build</h6> 
    <blockquote> 
     <p>Dockerfile 就是用来构建 docker 镜像的构建文件,命令脚本!<br> 通过这个脚本可以生成镜像,镜像是一层一层的,脚本一个个的命令。每一个命令都是一层。</p> 
    </blockquote> 
    <p>构建自己的镜像</p> 
    <pre data-index="45" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 创建一个dockerfile文件,名字可以随机,建议叫:dockerfile</span>
    <span class="token comment"># 文件中的内容 指令(大写)	参数</span>
    
    <span class="token comment"># 第一步,在本机的home目录新建一个docker-test-volume 目录</span>
    <span class="token namespace">[root@localhost home]</span><span class="token comment"># mkdir docker-test-volume</span>
    <span class="token namespace">[root@localhost home]</span><span class="token comment"># ls</span>
    ceshi  chenmaolin  chenxiansheng222<span class="token punctuation">.</span>java  docker-<span class="token function">test-volume</span>  juming  mysql
    
    <span class="token comment"># 第二部,进入到该目录,新建一个名为dockerfile1的文件,并写上内容</span>
    <span class="token namespace">[root@localhost home]</span><span class="token comment"># cd docker-test-volume/</span>
    <span class="token namespace">[root@localhost docker-test-volume]</span><span class="token comment"># vi dockerfile1</span>
    <span class="token namespace">[root@localhost docker-test-volume]</span><span class="token comment"># cat dockerfile1</span>
    <span class="token keyword">FROM</span> centos
    
    VOLUME <span class="token punctuation">[</span><span class="token string">"volume01"</span><span class="token punctuation">,</span><span class="token string">"volume02"</span><span class="token punctuation">]</span>
    
    CMD <span class="token function">echo</span> <span class="token string">"-------end------"</span>
    CMD <span class="token operator">/</span>bin/bash
    
    <span class="token comment"># 第三步,使用构建镜像的命,docker build</span>
    <span class="token operator">-</span>f 		<span class="token comment"># 指定要构建的文件</span>
    <span class="token operator">-</span>t 		<span class="token comment"># 要生成的镜像</span>
    <span class="token punctuation">.</span>		<span class="token comment"># 表示当前目录</span>
    <span class="token namespace">[root@localhost docker-test-volume]</span><span class="token comment"># docker build -f /home/docker-test-volume/dockerfile1 -t chenxiansheng/centos:1.0 .</span>
    Sending build context to Docker daemon  2<span class="token punctuation">.</span>048kB
    Step 1/4 : <span class="token keyword">FROM</span> centos
     <span class="token operator">--</span><span class="token operator">-</span>> 5d0da3dc9764
    Step 2/4 : VOLUME <span class="token punctuation">[</span><span class="token string">"volume01"</span><span class="token punctuation">,</span><span class="token string">"volume02"</span><span class="token punctuation">]</span>
     <span class="token operator">--</span><span class="token operator">-</span>> Running in de2d516d27b4
    Removing intermediate container de2d516d27b4
     <span class="token operator">--</span><span class="token operator">-</span>> ab91177ccd23
    Step 3/4 : CMD <span class="token function">echo</span> <span class="token string">"-------end------"</span>
     <span class="token operator">--</span><span class="token operator">-</span>> Running in da532b3a90af
    Removing intermediate container da532b3a90af
     <span class="token operator">--</span><span class="token operator">-</span>> 3dfd8b7d5bde
    Step 4/4 : CMD <span class="token operator">/</span>bin/bash
     <span class="token operator">--</span><span class="token operator">-</span>> Running in df8f5c472181
    Removing intermediate container df8f5c472181
     <span class="token operator">--</span><span class="token operator">-</span>> b0b6b03694f5
    Successfully built b0b6b03694f5
    Successfully tagged chenxiansheng/centos:1<span class="token punctuation">.</span>0
    
    <span class="token comment"># 第四步,查看镜像,可以看到自己的镜像构建成功,chenxiansheng/centos</span>
    <span class="token namespace">[root@localhost docker-test-volume]</span><span class="token comment"># docker images</span>
    REPOSITORY             TAG       IMAGE ID       CREATED         SIZE
    chenxiansheng/centos   1<span class="token punctuation">.</span>0       b0b6b03694f5   8 seconds ago   231MB
    chentomcat             1<span class="token punctuation">.</span>0       8c3fc729e0f1   3 days ago      684MB
    nginx                  latest    605c77e624dd   4 months ago    141MB
    tomcat                 9<span class="token punctuation">.</span>0       b8e65a4d736d   5 months ago    680MB
    tomcat                 latest    fb5657adc892   5 months ago    680MB
    mysql                  5<span class="token punctuation">.</span>7       c20987f18b13   5 months ago    448MB
    centos                 latest    5d0da3dc9764   8 months ago    231MB
    portainer/portainer    latest    580c0e4e98b0   14 months ago   79<span class="token punctuation">.</span>1MB
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li></ul></pre> 
    <blockquote> 
     <p>可以看到,这里构建镜像分成了四步,并且我们前面写的输出的一句话,也正常输出来了<br> -----end------<br> <img src="https://1000bd.com/contentImg/2023/11/04/155324940.png" alt="在这里插入图片描述"></p> 
    </blockquote> 
    <blockquote> 
     <p>启动自己镜像进行测试</p> 
    </blockquote> 
    <p><img src="https://1000bd.com/contentImg/2023/11/04/155325226.png" alt="在这里插入图片描述"></p> 
    <blockquote> 
     <p>但是上面的挂载有一个问题,那就我们并没有指定本机的目录,只是挂载的容器里的目录 volume01 和volume02 ,这是属于匿名挂载。所以它生成的本机目录是一窜很长的16进制表示的目录名。</p> 
    </blockquote> 
    <p>使用docker inspect 容器id 命令,查看该容器的进程信息,就可以得到该容器的进程信息,可以从进程信息找到该容器的挂载的本机目录</p> 
    <pre data-index="46" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost /]</span><span class="token comment"># docker inspect d0ea1e9cf82e</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
    <p>从进程信息中,找到mounts ,可以看到主机的目录<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325299.png" alt="在这里插入图片描述"><br> 跟前面的数据卷一样,文件也是双向绑定的。在容器里的volume01目录有变动,本机的/var/lib/docker/volumes/656e215f074529196d4b1b8df2e9339286b81bba49beebeb03ea2c483d25e902/_data 也会跟着同步。同理,volume02 也一样。</p> 
    <blockquote> 
     <p>以上这种构建dockerfile的方式未来我们用的十分多。因为偶们通常会构建自己的镜像!</p> 
    </blockquote> 
    <h5><a id="_1270"></a>数据卷容器</h5> 
    <p>就是多个容器间进行数据共享,使用–volumes-from 命令</p> 
    <p>第一步,启动一个docker01容器,就用我们前面自己构建的镜像</p> 
    <pre data-index="47" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost docker-test-volume]</span><span class="token comment"># docker run -it --name docker01 chenxiansheng/centos:1.0</span>
    <span class="token namespace">[root@cf7f334a2601 /]</span><span class="token comment"># ls -l</span>
    total 0
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   7 Nov  3  2020 bin <span class="token operator">-</span>> usr/bin
    drwxr-xr-x<span class="token punctuation">.</span>   5 root root 360 May 26 15:04 dev
    drwxr-xr-x<span class="token punctuation">.</span>   1 root root  66 May 26 15:04 etc
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 home
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   7 Nov  3  2020 lib <span class="token operator">-</span>> usr/lib
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   9 Nov  3  2020 lib64 <span class="token operator">-</span>> usr/lib64
    drwx-<span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token punctuation">.</span>   2 root root   6 Sep 15  2021 lost+found
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 media
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 mnt
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 opt
    dr-xr-xr-x<span class="token punctuation">.</span> 126 root root   0 May 26 15:04 proc
    dr-xr-x-<span class="token operator">--</span><span class="token punctuation">.</span>   2 root root 162 Sep 15  2021 root
    drwxr-xr-x<span class="token punctuation">.</span>  11 root root 163 Sep 15  2021 run
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   8 Nov  3  2020 sbin <span class="token operator">-</span>> usr/sbin
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 srv
    dr-xr-xr-x<span class="token punctuation">.</span>  13 root root   0 May 26 11:41 sys
    drwxrwxrwt<span class="token punctuation">.</span>   7 root root 171 Sep 15  2021 tmp
    drwxr-xr-x<span class="token punctuation">.</span>  12 root root 144 Sep 15  2021 usr
    drwxr-xr-x<span class="token punctuation">.</span>  20 root root 262 Sep 15  2021 <span class="token keyword">var</span>
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 May 26 15:04 volume01
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 May 26 15:04 volume02
    
    <span class="token comment"># 随后使用ctrl+P+Q ,后台运行并退出</span>
    <span class="token namespace">[root@cf7f334a2601 /]</span><span class="token comment"># [root@localhost docker-test-volume]#</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li></ul></pre> 
    <p>第二步,继承docker01镜像,启动一个docker02容器,使用–volumes-from 参数</p> 
    <pre data-index="48" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost docker-test-volume]</span><span class="token comment"># docker run -it --name docker02 --volumes-from docker01 chenxiansheng/centos:1.0</span>
    <span class="token namespace">[root@f0cc63e30a17 /]</span><span class="token comment"># ls -l</span>
    total 0
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   7 Nov  3  2020 bin <span class="token operator">-</span>> usr/bin
    drwxr-xr-x<span class="token punctuation">.</span>   5 root root 360 May 26 15:07 dev
    drwxr-xr-x<span class="token punctuation">.</span>   1 root root  66 May 26 15:07 etc
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 home
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   7 Nov  3  2020 lib <span class="token operator">-</span>> usr/lib
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   9 Nov  3  2020 lib64 <span class="token operator">-</span>> usr/lib64
    drwx-<span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token punctuation">.</span>   2 root root   6 Sep 15  2021 lost+found
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 media
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 mnt
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 opt
    dr-xr-xr-x<span class="token punctuation">.</span> 125 root root   0 May 26 15:07 proc
    dr-xr-x-<span class="token operator">--</span><span class="token punctuation">.</span>   2 root root 162 Sep 15  2021 root
    drwxr-xr-x<span class="token punctuation">.</span>  11 root root 163 Sep 15  2021 run
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   8 Nov  3  2020 sbin <span class="token operator">-</span>> usr/sbin
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 srv
    dr-xr-xr-x<span class="token punctuation">.</span>  13 root root   0 May 26 11:41 sys
    drwxrwxrwt<span class="token punctuation">.</span>   7 root root 171 Sep 15  2021 tmp
    drwxr-xr-x<span class="token punctuation">.</span>  12 root root 144 Sep 15  2021 usr
    drwxr-xr-x<span class="token punctuation">.</span>  20 root root 262 Sep 15  2021 <span class="token keyword">var</span>
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 May 26 15:04 volume01
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 May 26 15:04 volume02
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li></ul></pre> 
    <p>可以看到,docker01 和docker02 都拥有volume01 和volume02 目录, 这个两个目录是同步数据的,下面我们来测试一下:</p> 
    <pre data-index="49" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 我们在docker01 容器的volume01 目录新建一个 test.java </span>
    <span class="token namespace">[root@cf7f334a2601 /]</span><span class="token comment"># cd volume01/</span>
    <span class="token namespace">[root@cf7f334a2601 volume01]</span><span class="token comment"># ls</span>
    <span class="token namespace">[root@cf7f334a2601 volume01]</span><span class="token comment"># touch test.java</span>
    <span class="token namespace">[root@cf7f334a2601 volume01]</span><span class="token comment"># ls</span>
    test<span class="token punctuation">.</span>java
    <span class="token namespace">[root@cf7f334a2601 volume01]</span><span class="token comment"># </span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li></ul></pre> 
    <p>此时去到docker02 容器,查看volume01 文件,test.java文化也是存在的,这就实现了数据卷容器的同步功能</p> 
    <pre data-index="50" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@f0cc63e30a17 /]</span><span class="token comment"># cd volume01</span>
    <span class="token namespace">[root@f0cc63e30a17 volume01]</span><span class="token comment"># ls</span>
    test<span class="token punctuation">.</span>java
    <span class="token namespace">[root@f0cc63e30a17 volume01]</span><span class="token comment"># </span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
    <p>那么,如果我要同步容器3、容器4 呢,这里继续测试,我们继承docker02 ,启动docker03</p> 
    <pre data-index="51" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost ~]</span><span class="token comment"># docker run -it --name docker03 --volumes-from docker02 chenxiansheng/centos:1.0</span>
    <span class="token namespace">[root@97396699c735 /]</span><span class="token comment"># ls -l</span>
    total 0
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   7 Nov  3  2020 bin <span class="token operator">-</span>> usr/bin
    drwxr-xr-x<span class="token punctuation">.</span>   5 root root 360 May 26 15:18 dev
    drwxr-xr-x<span class="token punctuation">.</span>   1 root root  66 May 26 15:17 etc
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 home
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   7 Nov  3  2020 lib <span class="token operator">-</span>> usr/lib
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   9 Nov  3  2020 lib64 <span class="token operator">-</span>> usr/lib64
    drwx-<span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token punctuation">.</span>   2 root root   6 Sep 15  2021 lost+found
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 media
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 mnt
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 opt
    dr-xr-xr-x<span class="token punctuation">.</span> 130 root root   0 May 26 15:17 proc
    dr-xr-x-<span class="token operator">--</span><span class="token punctuation">.</span>   2 root root 162 Sep 15  2021 root
    drwxr-xr-x<span class="token punctuation">.</span>  11 root root 163 Sep 15  2021 run
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   8 Nov  3  2020 sbin <span class="token operator">-</span>> usr/sbin
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 srv
    dr-xr-xr-x<span class="token punctuation">.</span>  13 root root   0 May 26 11:41 sys
    drwxrwxrwt<span class="token punctuation">.</span>   7 root root 171 Sep 15  2021 tmp
    drwxr-xr-x<span class="token punctuation">.</span>  12 root root 144 Sep 15  2021 usr
    drwxr-xr-x<span class="token punctuation">.</span>  20 root root 262 Sep 15  2021 <span class="token keyword">var</span>
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root  23 May 26 15:11 volume01
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 May 26 15:04 volume02
    <span class="token namespace">[root@97396699c735 /]</span><span class="token comment"># cd volume01</span>
    <span class="token namespace">[root@97396699c735 volume01]</span><span class="token comment"># ls</span>
    test<span class="token punctuation">.</span>java
    <span class="token namespace">[root@97396699c735 volume01]</span><span class="token comment"># </span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li></ul></pre> 
    <p>可以看到,同步依然是有效的。<br> 如果docker03 继承docker01 启动,可不可以呢? 答案也是肯定的,也是能实现数据共享的!!<br> 删除了docker 01 后,docker02 和docker03 依然可以实现数据共享。跟容器是否启动是无关的!<br> 所以得出结论,要实现容器间的数据共享,只需要在docker run 增加–volumes-from 参数 父类容器名称 ,就可以实现容器间的数据共享。 只要有共同一个父类就可以。</p> 
    <blockquote> 
     <p>结论:容器之间配置信息的传递,数据卷容器的生命周期一直持续到没有容器使用为止<br> 但是一旦持久化到了本地,这个时候,本地的数据就不会删除,就算容器没有再使用了。</p> 
    </blockquote> 
    <h3><a name="t13"></a><a id="DockerFile_1396"></a>DockerFile</h3> 
    <h6><a id="dockerfIle_docker_1397"></a>dockerfIle 是用来构建docker镜像的文件!</h6> 
    <p>构建步骤:</p> 
    <ol><li>编写一个dockerfile文件</li><li>docker build 构建成为一个镜像</li><li>docker run 运行镜像</li><li>docker push 发布镜像(DockerHub 、阿里云镜像仓库等)</li></ol> 
    <p>很多官方的镜像都是基础包,很多功能没有,我们通常会自己搭建自己的镜像。</p> 
    <h3><a name="t14"></a><a id="DockerFile__1407"></a>DockerFile 构建过程</h3> 
    <h6><a id="_1408"></a>基础知识:</h6> 
    <ol><li>每个保留关键字(指令) 都是必须大写字母</li><li>执行从上到下顺序执行</li><li>#表示注释</li><li>每个指令都会创建提交一个新的镜像层,并提交!<br> 类似我们上面写的,dockerfile ,就是一层一层的<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325194.png" alt="在这里插入图片描述"><img src="https://1000bd.com/contentImg/2023/11/04/155325398.png" alt="在这里插入图片描述"><br> dockerfile 是面向开发的,我们以后发布项目,做镜像,就需要编写dockerfile 文件,这个文件十分简单!<br> Docker 镜像逐渐成为企业交付的标准。<br> 步骤: 开发,部署,运维<br> Dockerfile: 构建文件,定义了一切的步骤,源代码。<br> DockerImages: 通过Dockerfile 构建生成的镜像,最终发布和运行的产品!<br> Docker容器:容器就是镜像运行起来提供服务器</li></ol> 
    <h3><a name="t15"></a><a id="Dockerfile_1424"></a>Dockerfile的指令</h3> 
    <p>以下是各种命令的含义:<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325622.png" alt="在这里插入图片描述"></p> 
    <pre data-index="52" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">CMD 		<span class="token comment"># 指定这个容器启动的时候要运行的命令,只有最后一个会生效,可被替代</span>
    ENTRYPOINT	<span class="token comment"># 指定这个容器启动的时候要运行的命令,可以追加命令</span>
    ONBUILD		<span class="token comment"># 当构建一个被继承DockerFile 这个时候就会运行ONBUILD 的指令,触发指令</span>
    <span class="token function">COPY</span>		<span class="token comment"># 类似ADD,将我们文件拷贝到镜像中</span>
    ENY			<span class="token comment"># 构建的时候设置环境变量!</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
    <h5><a id="_1436"></a>实战测试</h5> 
    <p>Docker Hub 中99% 镜像都是从这个基础镜像过来的FROM scratch ,然后配置需要的软件和配置要进行的构建</p> 
    <p>我们先启动centos ,在容器里面使用 vim 命令和 ifconfig 命令,发现,都是不支持这个命令的,说明官方的centos容器是阉割版的,那我们就自己构建一个centos,是它能够支持vim 和ifconfig命令<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325705.png" alt="在这里插入图片描述"></p> 
    <h6><a id="centos_1442"></a>构建自己的centos</h6> 
    <p>创建目录,并在该目录新建一个mydockerfilecentos 文件,并且写上要构建的镜像指令</p> 
    <pre data-index="53" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost home]</span><span class="token comment"># mkdir firstdockerfile</span>
    <span class="token namespace">[root@localhost home]</span><span class="token comment"># ls</span>
    ceshi  chenmaolin  chenxiansheng222<span class="token punctuation">.</span>java  docker-<span class="token function">test-volume</span>  firstdockerfile  juming  mysql
    <span class="token namespace">[root@localhost home]</span><span class="token comment"># cd firstdockerfile/</span>
    
    <span class="token comment"># 1 编写Dockerfile 文件</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># vi mydockerfilecentos</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># cat mydockerfilecentos </span>
    <span class="token keyword">FROM</span> centos:7										<span class="token comment"># 指定了centos 为基础镜像,因为本机的centos版本就是7.9,所以这里也要下7,都则会下载不了</span>
    MAINTAINER chenxiansheng<1050480930@qq<span class="token punctuation">.</span>com>		<span class="token comment"># 维护者西你想</span>
    
    ENV MYPATH <span class="token operator">/</span>usr/local							<span class="token comment"># 设置环境变量</span>
    WORKDIR <span class="token variable">$MYPATH</span>									<span class="token comment"># 设置当前工作目录</span>
    
    RUN  yum <span class="token operator">-</span>y install vim 						<span class="token comment"># 默认下载vim指令</span>
    RUN  yum <span class="token operator">-</span>y insatll net-tools					<span class="token comment"># 默认下载网络工具包</span>
    
    EXPOSE 80										<span class="token comment"># 指定对外的端口</span>
    
    CMD <span class="token function">echo</span> <span class="token variable">$MYPATH</span>								<span class="token comment"># 容器启动时,要运行的命令,将工作目录打印出来</span>
    CMD <span class="token function">echo</span> <span class="token string">"----end------"</span>						<span class="token comment"># 容器启动时,要运行的命令</span>
    CMD <span class="token operator">/</span>bin/bash 									<span class="token comment"># 容器启动时,要启动的命令行</span>
    
    <span class="token comment"># 2、通过这个文件构建镜像</span>
    <span class="token comment"># 命令	docker build -f dockerfile文件路径</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker build -f mydockerfilecentos -t mycentos:0.1 .</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li></ul></pre> 
    <p>构建成功<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325750.png" alt="在这里插入图片描述"></p> 
    <blockquote> 
     <p>注意查看docker容器里面的centos版本是不是8.0,本机的centos是7.9的情况,这种时候构建遇到 yum命令时会报错,需要在dockerfile文件中,指定下载为7版本的centos,即可解决</p> 
    </blockquote> 
    <pre data-index="54" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 3、 测试运行</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker run -it mycentos:0.1</span>
    
    <span class="token comment"># 这里可以看到,容器默认就是进入到/usr/local,这就是我们前面设置的工作目录</span>
    <span class="token namespace">[root@547054def8e6 local]</span><span class="token comment"># pwd</span>
    <span class="token operator">/</span>usr/local
    
    <span class="token comment"># 可以看到我们构建的镜像,可以使用ifconifg、vim命令了</span>
    <span class="token namespace">[root@547054def8e6 local]</span><span class="token comment"># ifconfig  </span>
    eth0: flags=4163<UP<span class="token punctuation">,</span>BROADCAST<span class="token punctuation">,</span>RUNNING<span class="token punctuation">,</span>MULTICAST>  mtu 1500
            inet 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>0<span class="token punctuation">.</span>4  netmask 255<span class="token punctuation">.</span>255<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0  broadcast 172<span class="token punctuation">.</span>17<span class="token punctuation">.</span>255<span class="token punctuation">.</span>255
            ether 02:42:<span class="token function">ac</span>:11:00:04  txqueuelen 0  <span class="token punctuation">(</span>Ethernet<span class="token punctuation">)</span>
            RX packets 8  bytes 656 <span class="token punctuation">(</span>656<span class="token punctuation">.</span>0 B<span class="token punctuation">)</span>
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 <span class="token punctuation">(</span>0<span class="token punctuation">.</span>0 B<span class="token punctuation">)</span>
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP<span class="token punctuation">,</span>LOOPBACK<span class="token punctuation">,</span>RUNNING>  mtu 65536
            inet 127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1  netmask 255<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0
            loop  txqueuelen 1000  <span class="token punctuation">(</span>Local Loopback<span class="token punctuation">)</span>
            RX packets 0  bytes 0 <span class="token punctuation">(</span>0<span class="token punctuation">.</span>0 B<span class="token punctuation">)</span>
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 <span class="token punctuation">(</span>0<span class="token punctuation">.</span>0 B<span class="token punctuation">)</span>
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    <span class="token namespace">[root@547054def8e6 local]</span><span class="token comment">#vim  </span>
    <span class="token namespace">[root@547054def8e6 local]</span><span class="token comment">#   </span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li></ul></pre> 
    <h6><a id="docker_history_id__dockerfile_1508"></a>使用docker history 镜像id 来查看dockerfile变更历史</h6> 
    <p>我们平时拿到一个镜像,可以研究一下它是怎么做的</p> 
    <pre data-index="55" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker images</span>
    REPOSITORY             TAG       IMAGE ID       CREATED          SIZE
    mycentos               0<span class="token punctuation">.</span>1       c80a46b4bab7   12 minutes ago   601MB
    
    <span class="token comment"># 使用镜像id查看变更历史(也就是可以查看这些镜像的dockerfile是怎么写的)</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker history c80a46b4bab7</span>
    IMAGE          CREATED          CREATED BY                                      SIZE      COMMENT
    c80a46b4bab7   13 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop)  CMD ["/bin/sh" "-c" "/bin…   0B        </span>
    522954b80b85   13 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop)  CMD ["/bin/sh" "-c" "echo…   0B        </span>
    dfcfc1df60c5   13 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop)  CMD ["/bin/sh" "-c" "echo…   0B        </span>
    a04211a9bee4   13 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop)  EXPOSE 80                    0B        </span>
    536afb4c9003   13 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c yum <span class="token operator">-</span>y install net-tools             171MB     
    497262217236   13 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c yum <span class="token operator">-</span>y install vim                   226MB     
    f4d69a0c750d   20 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop) WORKDIR /usr/local            0B        </span>
    098b9103d5fb   20 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop)  ENV MYPATH=/usr/local        0B        </span>
    722b4df5b913   20 minutes ago   <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop)  MAINTAINER chenxiansheng<…   0B        </span>
    eeb6ee3f44bd   8 months ago     <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop)  CMD ["/bin/bash"]            0B        </span>
    <missing>      8 months ago     <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop)  LABEL org.label-schema.sc…   0B        </span>
    <missing>      8 months ago     <span class="token operator">/</span>bin/sh <span class="token operator">-</span>c <span class="token comment">#(nop) ADD file:b3ebbe8bd304723d4…   204MB     </span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># </span>
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li></ul></pre> 
    <blockquote> 
     <p>CMD 和 ENTRYPOINT 区别</p> 
    </blockquote> 
    <pre data-index="56" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;">CMD 			<span class="token comment"># 指定这个容器启动的时候要运行的命令,只有最后一个会生效,可被替代</span>
    ENTRYPOINT		<span class="token comment"># 指定这个容器启动的时候要运行的命令,可以追加命令</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
    <p>测试cmd</p> 
    <pre data-index="57" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 构建dockerfile镜像</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># vi dockerfile-cmd-test</span>
    
    <span class="token comment"># 这里的镜像就只运行 ls -a 命令</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># cat dockerfile-cmd-test </span>
    <span class="token keyword">FROM</span> centos
    CMD <span class="token punctuation">[</span><span class="token string">"ls"</span><span class="token punctuation">,</span><span class="token string">"-a"</span><span class="token punctuation">]</span>
    
    <span class="token comment"># 构建cmd镜像</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker build -f dockerfile-cmd-test -t cmdtest .</span>
    Sending build context to Docker daemon  3<span class="token punctuation">.</span>072kB
    Step 1/2 : <span class="token keyword">FROM</span> centos
     <span class="token operator">--</span><span class="token operator">-</span>> 5d0da3dc9764
    Step 2/2 : CMD <span class="token punctuation">[</span><span class="token string">"ls"</span><span class="token punctuation">,</span><span class="token string">"-a"</span><span class="token punctuation">]</span>
     <span class="token operator">--</span><span class="token operator">-</span>> Running in 82f7e399a1f0
    Removing intermediate container 82f7e399a1f0
     <span class="token operator">--</span><span class="token operator">-</span>> 0b2e5b872f1c
    Successfully built 0b2e5b872f1c
    Successfully tagged cmdtest:latest
    
    <span class="token comment"># 运行cmd镜像</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker run 0b2e5b872f1c</span>
    <span class="token punctuation">.</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token punctuation">.</span>dockerenv
    bin
    dev
    etc
    home
    lib
    lib64
    lost+found
    media
    mnt
    opt
    proc
    root
    run
    sbin
    srv
    sys
    tmp
    usr
    <span class="token keyword">var</span>
    
    <span class="token comment"># 上面可以看到,正确执行了 ls -a 命令,下面我们想要追加一个命令,变成 ls -l </span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker run 0b2e5b872f1c -l</span>
    docker: Error response <span class="token keyword">from</span> daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to <span class="token function">start</span> container <span class="token keyword">process</span>: exec: <span class="token string">"-l"</span>: executable file not found in <span class="token variable">$PATH</span>: unknown<span class="token punctuation">.</span>
    
    <span class="token comment"># cmd 的清理下,会用-l 替换 ["ls","-a"] 命令, 因为-l 不是命令,所以报错了</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li></ul></pre> 
    <p>测试ENTRYPOINT</p> 
    <pre data-index="58" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 构建dockerfile镜像</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># vi docker-entrypoint-test</span>
    
    <span class="token comment"># 这里和上面一样,该镜像只执行ls -a 命令</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># cat docker-entrypoint-test </span>
    <span class="token keyword">FROM</span> centos
    ENTRYPOINT <span class="token punctuation">[</span><span class="token string">"ls"</span><span class="token punctuation">,</span><span class="token string">"-a"</span><span class="token punctuation">]</span>
    
    <span class="token comment"># 构建entrypoint 镜像</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker build -f docker-entrypoint-test -t entrypointtest .</span>
    Sending build context to Docker daemon  4<span class="token punctuation">.</span>096kB
    Step 1/2 : <span class="token keyword">FROM</span> centos
     <span class="token operator">--</span><span class="token operator">-</span>> 5d0da3dc9764
    Step 2/2 : ENTRYPOINT <span class="token punctuation">[</span><span class="token string">"ls"</span><span class="token punctuation">,</span><span class="token string">"-a"</span><span class="token punctuation">]</span>
     <span class="token operator">--</span><span class="token operator">-</span>> Running in 221b27881ee1
    Removing intermediate container 221b27881ee1
     <span class="token operator">--</span><span class="token operator">-</span>> 3cdb2e38bcd8
    Successfully built 3cdb2e38bcd8
    Successfully tagged entrypointtest:latest
    
    <span class="token comment"># 运行entrypoint 镜像,可以发现,运行成功</span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker run 3cdb2e38bcd8</span>
    <span class="token punctuation">.</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token punctuation">.</span>dockerenv
    bin
    dev
    etc
    home
    lib
    lib64
    lost+found
    media
    mnt
    opt
    proc
    root
    run
    sbin
    srv
    sys
    tmp
    usr
    <span class="token keyword">var</span>
    
    <span class="token comment"># 继续追加命令,直接在后面加 -l </span>
    <span class="token namespace">[root@localhost firstdockerfile]</span><span class="token comment"># docker run 3cdb2e38bcd8 -l</span>
    total 0
    drwxr-xr-x<span class="token punctuation">.</span>   1 root root   6 May 30 14:45 <span class="token punctuation">.</span>
    drwxr-xr-x<span class="token punctuation">.</span>   1 root root   6 May 30 14:45 <span class="token punctuation">.</span><span class="token punctuation">.</span>
    <span class="token operator">-</span>rwxr-xr-x<span class="token punctuation">.</span>   1 root root   0 May 30 14:45 <span class="token punctuation">.</span>dockerenv
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   7 Nov  3  2020 bin <span class="token operator">-</span>> usr/bin
    drwxr-xr-x<span class="token punctuation">.</span>   5 root root 340 May 30 14:45 dev
    drwxr-xr-x<span class="token punctuation">.</span>   1 root root  66 May 30 14:45 etc
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 home
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   7 Nov  3  2020 lib <span class="token operator">-</span>> usr/lib
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   9 Nov  3  2020 lib64 <span class="token operator">-</span>> usr/lib64
    drwx-<span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token punctuation">.</span>   2 root root   6 Sep 15  2021 lost+found
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 media
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 mnt
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 opt
    dr-xr-xr-x<span class="token punctuation">.</span> 135 root root   0 May 30 14:45 proc
    dr-xr-x-<span class="token operator">--</span><span class="token punctuation">.</span>   2 root root 162 Sep 15  2021 root
    drwxr-xr-x<span class="token punctuation">.</span>  11 root root 163 Sep 15  2021 run
    lrwxrwxrwx<span class="token punctuation">.</span>   1 root root   8 Nov  3  2020 sbin <span class="token operator">-</span>> usr/sbin
    drwxr-xr-x<span class="token punctuation">.</span>   2 root root   6 Nov  3  2020 srv
    dr-xr-xr-x<span class="token punctuation">.</span>  13 root root   0 May 30 11:07 sys
    drwxrwxrwt<span class="token punctuation">.</span>   7 root root 171 Sep 15  2021 tmp
    drwxr-xr-x<span class="token punctuation">.</span>  12 root root 144 Sep 15  2021 usr
    drwxr-xr-x<span class="token punctuation">.</span>  20 root root 262 Sep 15  2021 <span class="token keyword">var</span>
    
    <span class="token comment"># 结果:-l 命令执行成功了,是因为 他只是替换了-a ,变成了 ls -l 了。所以成功运行</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li><li style="color: rgb(153, 153, 153);">69</li><li style="color: rgb(153, 153, 153);">70</li><li style="color: rgb(153, 153, 153);">71</li><li style="color: rgb(153, 153, 153);">72</li></ul></pre> 
    <h3><a name="t16"></a><a id="Tomcat__1673"></a>实战:Tomcat 镜像</h3> 
    <p>1、准备镜像文件,tomcat压缩包,jdk压缩包<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325103.png" alt="在这里插入图片描述"><br> 2、新建readme.txt,Dockerfile文件 ,并且填写dockerfile指令(这里我们是要建一个tomcat 和jdk的镜像),随后构建写好的dockerfile文件</p> 
    <pre data-index="59" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># touch readme.txt</span>
    <span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># vi Dockerfile</span>
    
    <span class="token comment"># 填写dockerfile指令,这里我们是要建一个tomcat 和jdk的镜像</span>
    <span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># cat Dockerfile </span>
    <span class="token keyword">FROM</span> centos:7
    MAINTAINER chenxiansheng<1050480930@qq<span class="token punctuation">.</span>com>
    
    <span class="token function">COPY</span> readme<span class="token punctuation">.</span>txt <span class="token operator">/</span>usr/local/readme<span class="token punctuation">.</span>txt
    
    ADD jdk-8u60-linux-x64<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz <span class="token operator">/</span>usr/local/
    ADD apache-tomcat-9<span class="token punctuation">.</span>0<span class="token punctuation">.</span>63<span class="token punctuation">.</span>tar<span class="token punctuation">.</span>gz <span class="token operator">/</span>usr/local/
    
    RUN yum <span class="token operator">-</span>y install vim 
    
    ENV MYPATH <span class="token operator">/</span>usr/local
    WORKDIR <span class="token variable">$MYPATH</span>
    
    ENV JAVA_HOME <span class="token operator">/</span>usr/local/jdk1<span class="token punctuation">.</span>8<span class="token punctuation">.</span>0_60
    ENV CLASSPATH <span class="token variable">$JAVA_HOME</span><span class="token operator">/</span>lib/dt<span class="token punctuation">.</span>jar:<span class="token variable">$JAVA_HOME</span><span class="token operator">/</span>lib/tools<span class="token punctuation">.</span>jar
    ENV CATALINA_HOME <span class="token operator">/</span>usr/local/apache-tomcat-9<span class="token punctuation">.</span>0<span class="token punctuation">.</span>63
    ENV CATALINA_BASH <span class="token operator">/</span>usr/local/apache-tomcat-9<span class="token punctuation">.</span>0<span class="token punctuation">.</span>63
    ENV PATH <span class="token variable">$PATH</span>:<span class="token variable">$JAVA_HOME</span><span class="token operator">/</span>bin:<span class="token variable">$CATAINA_HOME</span><span class="token operator">/</span>lib:<span class="token variable">$CATALINA_HOME</span><span class="token operator">/</span>bin
    
    
    EXPOSE 8080
    
    CMD <span class="token operator">/</span>usr/local/apache-tomcat-9<span class="token punctuation">.</span>0<span class="token punctuation">.</span>63/bin/startup<span class="token punctuation">.</span>sh && tail <span class="token operator">-</span>F <span class="token operator">/</span>usr/local/apache-tomcat-9<span class="token punctuation">.</span>0<span class="token punctuation">.</span>63/bin/logs/catalina<span class="token punctuation">.</span>out
    
    
    <span class="token comment"># 开始构建dockerfile(这里的“.” 代表构建当前目录下的Dockfile文件)</span>
    <span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker build -t diytomcat .</span>
    Sending build context to Docker daemon  192<span class="token punctuation">.</span>8MB
    Step 1/15 : <span class="token keyword">FROM</span> centos:7
     <span class="token operator">--</span><span class="token operator">-</span>> eeb6ee3f44bd
    Step 2/15 : MAINTAINER chenxiansheng<1050480930@qq<span class="token punctuation">.</span>com>
     <span class="token operator">--</span><span class="token operator">-</span>> <span class="token keyword">Using</span> cache
     <span class="token operator">--</span><span class="token operator">-</span>> 722b4df5b913
    <span class="token comment">#....... 省略构建日志</span>
    Successfully built 7c5296e1e145
    Successfully tagged diytomcat:latest
    
    <span class="token comment"># 查看镜像,可以发现,我们的diytomcat 构建成功</span>
    <span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker images</span>
    REPOSITORY             TAG       IMAGE ID       CREATED         SIZE
    diytomcat              latest    7c5296e1e145   2 minutes ago   811MB
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li></ul></pre> 
    <p>第3步、启动该镜像</p> 
    <pre data-index="60" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker run -d -p 9090:8080 --name chenxianshengtomcat -v /home/tomcat/test:/usr/local/apache-tomcat-9.0.63/webapps/test -v /home/tomcat/tomcatlogs/:/usr/local/apache-tomcat-9.0.63/logs diytomcat</span>
    49b22d1db8763cee40876a75a4ed11cebdc51462153f981253d1a04582cca618
    
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
    <p>镜像 启动参数说明:<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325392.png" alt="在这里插入图片描述"><img src="https://1000bd.com/contentImg/2023/11/04/155325580.png" alt=""></p> 
    <p>第4步,开始测试,tomcat是否成功</p> 
    <p>直接去访问linux地址的9090端口,查看是否有tomcat 页面:<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325783.png" alt="在这里插入图片描述"><br> 可以看到,tomcat是正常运行的</p> 
    <p>第五步。继续测试tomcat ,因为我们在启动自己制作的diytomcat镜像时,将本机的/home/tomcat/test 目录与容器里面的/usr/local/apache-tomcat-9.0.63/webapps/test 绑定了,所以,我们直接往本机的/home/tomcat/test 目录,新增index.jsp ,那么容器的apache-tomcat-9.0.63/webapps/test 目录也是会有index.jsp文件的,这时候去访问本机地址:9090/test 地址,是会识别到index.jsp文件的,并把里面的内容解析成网页的。</p> 
    <p>1)进入到本机的/home/tomcat/test目录,新建index.jsp ,并且填上内容:</p> 
    <pre data-index="61" class="set-code-hide prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># cd test/</span>
    <span class="token namespace">[root@localhost test]</span><span class="token comment"># vi index.jsp</span>
    <span class="token namespace">[root@localhost test]</span><span class="token comment"># cat index.jsp </span>
    <<span class="token operator">%</span>@ page language=<span class="token string">"java"</span> contentType=<span class="token string">"text/html; charset=UTF-8"</span>
        pageEncoding=<span class="token string">"UTF-8"</span><span class="token operator">%</span>>
    <<span class="token operator">!</span>DOCTYPE html>
    <html>
    <head>
    <meta charset=<span class="token string">"utf-8"</span>>
    <title>chenxiansheng<span class="token punctuation">(</span>runoob<span class="token punctuation">.</span>com<span class="token punctuation">)</span><<span class="token operator">/</span>title>
    <<span class="token operator">/</span>head>
    <body>
    Hello World<span class="token punctuation">,</span>chenxiansheng!<br/>
    <<span class="token operator">%</span>
    out<span class="token punctuation">.</span>println<span class="token punctuation">(</span><span class="token string">"--------my test web logs-------"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token operator">%</span>>
    <<span class="token operator">/</span>body>
    <<span class="token operator">/</span>html>
    
    <span class="token comment"># 查看该容器是否也同步了index.jsp文件,可以看到同步成功</span>
    <span class="token namespace">[root@localhost tomcat]</span><span class="token comment"># docker exec -it 49b22d1db8763 /bin/bash</span>
    <span class="token namespace">[root@49b22d1db876 local]</span><span class="token comment"># cd /usr/local/apache-tomcat-9.0.63/webapps/test/</span>
    <span class="token namespace">[root@49b22d1db876 test]</span><span class="token comment"># ls</span>
    index<span class="token punctuation">.</span>jsp
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{"spm":"1001.2101.3001.7365"}"><img class="look-more-preCode contentImg-no-view" src="https://1000bd.com/contentImg/2022/06/27/191644837.png" alt="" title=""></span></div><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li></ul></pre> 
    <p>2) 直接访问本地地址:9090/test 路径<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325060.png" alt="在这里插入图片描述"><br> 可以看到,容器里面的tomcat正确的解析了index.jsp文件,生成了网页。并且我们可以去本机查看容器里面的logs日志(这个也是在启动该镜像的时候绑定好的)</p> 
    <p><img src="https://1000bd.com/contentImg/2023/11/04/155325923.png" alt="在这里插入图片描述"></p> 
    <blockquote> 
     <p>结论1:该diytomcat镜像,是我们自己一手打造出来的,实现了tomcat镜像该有的功能。</p> 
    </blockquote> 
    <blockquote> 
     <p>结论2:通过这种双向绑定的方式,我们的linux本机不需要安装tomcat镜像,只需要将其中的一个目录绑定在有tomcat的docker容器里,我们就可以实现,在本机上传web工程,让docker容器解析的功能。</p> 
    </blockquote> 
    <h3><a name="t17"></a><a id="_1783"></a>发布自己的镜像</h3> 
    <p>1、地址 https://hub.docker.com/ 注册自己账号<br> 2、确定这个账号可以登录<br> 3、在我们的服务器上提交自己的镜像</p> 
    <pre data-index="62" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token comment"># 使用docker login 命令 </span>
    <span class="token namespace">[root@localhost tomcatlogs]</span><span class="token comment"># docker login -u morningchan</span>
    Password: 
    WARNING! Your password will be stored unencrypted in <span class="token operator">/</span>root/<span class="token punctuation">.</span>docker/config<span class="token punctuation">.</span>json<span class="token punctuation">.</span>
    Configure a credential helper to remove this warning<span class="token punctuation">.</span> See
    https:<span class="token operator">/</span><span class="token operator">/</span>docs<span class="token punctuation">.</span>docker<span class="token punctuation">.</span>com/engine/reference/commandline/login/<span class="token comment">#credentials-store</span>
    
    Login Succeeded
    <span class="token namespace">[root@localhost tomcatlogs]</span><span class="token comment"># </span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li></ul></pre> 
    <p>登录成功后,需要修改tag ,也就是给自己的镜像一个版本号,使用docker tag 命令</p> 
    <pre data-index="63" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost tomcatlogs]</span><span class="token comment"># docker tag  7c5296e1e145 morningchan/diytomcat:1.0</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
    <p>推送自己的镜像到docker hub ,使用docker push 命令</p> 
    <pre data-index="64" class="set-code-show prettyprint"><code class="prism language-powershell has-numbering" onclick="mdcp.signin(event)" style="position: unset;"><span class="token namespace">[root@localhost tomcatlogs]</span><span class="token comment"># docker push morning/diytomcat:1.0</span>
    <div class="hljs-button signin" data-title="登录后复制" data-report-click="{"spm":"1001.2101.3001.4334"}"></div></code><ul class="pre-numbering" style="opacity: 0.650989;"><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
    <blockquote> 
     <p>注意:修改tag的时候,最好修改成自己dockerhub 用户名字/ 镜像名称的形式, 如果前面用户自己的docker hub镜像命名,那后面push就会被拒绝。 这里我的docker hub 用户名就叫morningchan ,</p> 
    </blockquote> 
    <p>可以看到,push 成功(这里速度太慢了,毕竟国外的网站)<br> <img src="https://1000bd.com/contentImg/2023/11/04/155325855.png" alt="在这里插入图片描述"></p>
                    </div>
                        </div>
                    </li>
    
                    <li class="list-group-item ul-li">
    
                        <b>相关阅读:</b><br>
                        <nobr>
    <a href="/Article/Index/953012">机器人地面站-[QGroundControl源码解析]-[3]-[ADSB]</a>                            <br />
    <a href="/Article/Index/1738306">Kubernetes (K8s) 底层原理</a>                            <br />
    <a href="/Article/Index/1421268">51单片机复位电容计算与分析(附带Proteus电路图)</a>                            <br />
    <a href="/Article/Index/1272305">Java对Reids的常用操作</a>                            <br />
    <a href="/Article/Index/1106554">MATLAB嵌套if语句</a>                            <br />
    <a href="/Article/Index/1406446">通过添加注解实现按顺序输出类属性</a>                            <br />
    <a href="/Article/Index/1330399">BASH shell脚本篇4——函数</a>                            <br />
    <a href="/Article/Index/1099528">【Python】输入输出与运算符</a>                            <br />
    <a href="/Article/Index/1161704">【机器学习】之第五章——神经网络</a>                            <br />
    <a href="/Article/Index/1132471">数字信号处理-2-三角函数与谱</a>                            <br />
                        </nobr>
                    </li>
                    <li class="list-group-item from-a mb-2">
                        原文地址:https://blog.csdn.net/chenmaolin928/article/details/124890653
                    </li>
    
                </ul>
            </div>
    
            <div class="col-lg-4 col-sm-12">
                <ul class="list-group" style="word-break:break-all;">
                    <li class="list-group-item ul-li-bg" aria-current="true">
                        最新文章
                    </li>
                    <li class="list-group-item ul-li">
                        <nobr>
    <a href="/Article/Index/1484446">攻防演习之三天拿下官网站群</a>                            <br />
    <a href="/Article/Index/1515268">数据安全治理学习——前期安全规划和安全管理体系建设</a>                            <br />
    <a href="/Article/Index/1759065">企业安全 | 企业内一次钓鱼演练准备过程</a>                            <br />
    <a href="/Article/Index/1485036">内网渗透测试 | Kerberos协议及其部分攻击手法</a>                            <br />
    <a href="/Article/Index/1877332">0day的产生 | 不懂代码的"代码审计"</a>                            <br />
    <a href="/Article/Index/1887576">安装scrcpy-client模块av模块异常,环境问题解决方案</a>                            <br />
    <a href="/Article/Index/1887578">leetcode hot100【LeetCode 279. 完全平方数】java实现</a>                            <br />
    <a href="/Article/Index/1887512">OpenWrt下安装Mosquitto</a>                            <br />
    <a href="/Article/Index/1887520">AnatoMask论文汇总</a>                            <br />
    <a href="/Article/Index/1887496">【AI日记】24.11.01 LangChain、openai api和github copilot</a>                            <br />
                        </nobr>
                    </li>
                </ul>
    
                <ul class="list-group pt-2" style="word-break:break-all;">
                    <li class="list-group-item ul-li-bg" aria-current="true">
                        热门文章
                    </li>
                    <li class="list-group-item ul-li">
                        <nobr>
    <a href="/Article/Index/888177">十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!</a>                            <br />
    <a href="/Article/Index/797680">奉劝各位学弟学妹们,该打造你的技术影响力了!</a>                            <br />
    <a href="/Article/Index/888183">五年了,我在 CSDN 的两个一百万。</a>                            <br />
    <a href="/Article/Index/888179">Java俄罗斯方块,老程序员花了一个周末,连接中学年代!</a>                            <br />
    <a href="/Article/Index/797730">面试官都震惊,你这网络基础可以啊!</a>                            <br />
    <a href="/Article/Index/797725">你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法</a>                            <br />
    <a href="/Article/Index/797702">心情不好的时候,用 Python 画棵樱花树送给自己吧</a>                            <br />
    <a href="/Article/Index/797709">通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!</a>                            <br />
    <a href="/Article/Index/797716">13 万字 C 语言从入门到精通保姆级教程2021 年版</a>                            <br />
    <a href="/Article/Index/888192">10行代码集2000张美女图,Python爬虫120例,再上征途</a>                            <br />
                        </nobr>
                    </li>
                </ul>
    
            </div>
        </div>
    </div>
    <!-- 主体 -->
    
    
        <!--body结束-->
        <!--这里是footer模板-->
        
        <!--footer-->
    <nav class="navbar navbar-inverse navbar-fixed-bottom">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="text-muted center foot-height">
                        Copyright © 2022 侵权请联系<a href="mailto:2656653265@qq.com">2656653265@qq.com</a>   
                        <a href="https://beian.miit.gov.cn/" target="_blank">京ICP备2022015340号-1</a>
                    </div>
                    <div style="width:300px;margin:0 auto; padding:0px 5px;">
                        <a href="/regex.html">正则表达式工具</a>
                        <a href="/cron.html">cron表达式工具</a>
                        <a href="/pwdcreator.html">密码生成工具</a>
                    </div>
                    <div style="width:300px;margin:0 auto; padding:5px 0;">
                        <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010502049817" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
                        <img src="" style="float:left;" /><p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">京公网安备 11010502049817号</p></a>
                    </div>
                </div>
            </div>
        </div>
      
    </nav>
    <!--footer-->
    
        <!--footer模板结束-->
    
        <script src="/js/plugins/jquery/jquery.js"></script>
        <script src="/js/bootstrap.min.js"></script>
    
        <!--这里是scripts模板-->
        
    
        
     
    
    
        <!--scripts模板结束-->
    
    </body>
    </html>