Docker - 镜像 | 容器 | 数据卷 日常开发常用指令 + 演示(一文通关)

目录

Docker 开发常用指令汇总

辅助命令

docker version

docker info

docker --help

镜像命令

查看镜像信息

下载镜像

搜索镜像

删除镜像

容器命令

查看运行中的容器

运行容器

停止、启动、重启、暂停、恢复容器

杀死容器

删除容器

查看容器日志

进入容器内部

容器与宿主机之间的文件拷贝

如何部署一个 web 项目(war 包项目)

查看容器内运行的进程信息

查看容器内部细节

数据卷

作用&使用场景&注意事项

容器启动时指定数据卷

查看 docker 所有数据卷

创建一个别名数据卷

查看数据卷详细内容

删除一个数据卷

容器打包镜像

背景

将容器打包成一个新的镜像

镜像的备份和恢复


Docker 开发常用指令汇总


辅助命令

docker version

用来查看 docker 客户端引擎 和 server 端引擎版本信息

[root@VM-8-17-centos ~]# docker version
Client: Docker Engine - CommunityVersion:           24.0.7API version:       1.43Go version:        go1.20.10Git commit:        afdd53bBuilt:             Thu Oct 26 09:11:35 2023OS/Arch:           linux/amd64Context:           defaultServer: Docker Engine - CommunityEngine:Version:          24.0.7API version:      1.43 (minimum version 1.12)Go version:       go1.20.10Git commit:       311b9ffBuilt:            Thu Oct 26 09:10:36 2023OS/Arch:          linux/amd64Experimental:     falsecontainerd:Version:          1.6.24GitCommit:        61f9fd88f79f081d64d6fa3bb1a0dc71ec870523runc:Version:          1.1.9GitCommit:        v1.1.9-0-gccaecfcdocker-init:Version:          0.19.0GitCommit:        de40ad0

docker info

用来查看 docker 引擎详细信息

[root@VM-8-17-centos ~]# docker info
Client: Docker Engine - CommunityVersion:    24.0.7Context:    defaultDebug Mode: falsePlugins:buildx: Docker Buildx (Docker Inc.)Version:  v0.11.2Path:     /usr/libexec/docker/cli-plugins/docker-buildxcompose: Docker Compose (Docker Inc.)Version:  v2.21.0Path:     /usr/libexec/docker/cli-plugins/docker-composeServer:Containers: 4Running: 4Paused: 0Stopped: 0Images: 8Server Version: 24.0.7Storage Driver: overlay2Backing Filesystem: extfsSupports d_type: trueUsing metacopy: falseNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: io.containerd.runc.v2 runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523runc version: v1.1.9-0-gccaecfcinit version: de40ad0Security Options:seccompProfile: builtinKernel Version: 3.10.0-1160.99.1.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 2Total Memory: 1.952GiBName: VM-8-17-centosID: 38c01492-c895-4bbc-8e2e-a575241b4201Docker Root Dir: /var/lib/dockerDebug Mode: falseExperimental: falseInsecure Registries:127.0.0.0/8Registry Mirrors:https://q9n10oke.mirror.aliyuncs.com/Live Restore Enabled: false

docker --help

用来查看帮助文档,给出了对于不同指令的解释

[root@VM-8-17-centos ~]# docker --helpUsage:  docker [OPTIONS] COMMANDA self-sufficient runtime for containersCommon Commands:run         Create and run a new container from an imageexec        Execute a command in a running containerps          List containersbuild       Build an image from a Dockerfilepull        Download an image from a registrypush        Upload an image to a registryimages      List imageslogin       Log in to a registrylogout      Log out from a registrysearch      Search Docker Hub for imagesversion     Show the Docker version informationinfo        Display system-wide informationManagement Commands:builder     Manage buildsbuildx*     Docker Buildx (Docker Inc., v0.11.2)compose*    Docker Compose (Docker Inc., v2.21.0)container   Manage containerscontext     Manage contextsimage       Manage imagesmanifest    Manage Docker image manifests and manifest listsnetwork     Manage networksplugin      Manage pluginssystem      Manage Dockertrust       Manage trust on Docker imagesvolume      Manage volumesSwarm Commands:swarm       Manage SwarmCommands:attach      Attach local standard input, output, and error streams to a running containercommit      Create a new image from a container's changescp          Copy files/folders between a container and the local filesystemcreate      Create a new containerdiff        Inspect changes to files or directories on a container's filesystemevents      Get real time events from the serverexport      Export a container's filesystem as a tar archivehistory     Show the history of an imageimport      Import the contents from a tarball to create a filesystem imageinspect     Return low-level information on Docker objectskill        Kill one or more running containersload        Load an image from a tar archive or STDINlogs        Fetch the logs of a containerpause       Pause all processes within one or more containersport        List port mappings or a specific mapping for the containerrename      Rename a containerrestart     Restart one or more containersrm          Remove one or more containersrmi         Remove one or more imagessave        Save one or more images to a tar archive (streamed to STDOUT by default)start       Start one or more stopped containersstats       Display a live stream of container(s) resource usage statisticsstop        Stop one or more running containerstag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGEtop         Display the running processes of a containerunpause     Unpause all processes within one or more containersupdate      Update configuration of one or more containerswait        Block until one or more containers stop, then print their exit codesGlobal Options:--config string      Location of client config files (default "/root/.docker")-c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")-D, --debug              Enable debug mode-H, --host list          Daemon socket to connect to-l, --log-level string   Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")--tls                Use TLS; implied by --tlsverify--tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")--tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")--tlskey string      Path to TLS key file (default "/root/.docker/key.pem")--tlsverify          Use TLS and verify the remote-v, --version            Print version information and quitRun 'docker COMMAND --help' for more information on a command.For more help on how to use Docker, head to https://docs.docker.com/go/guides/

镜像命令

查看镜像信息

查看当前本地仓库中存在哪些镜像.

docker images -q | 镜像名
// -q 和 镜像名 是可选参数

a)docker images 就是 docker image ls 的缩写,用来镜像以及信息

[root@VM-8-17-centos ~]# docker images
REPOSITORY                  TAG              IMAGE ID       CREATED       SIZE
redis                       5                c5da061a611a   2 years ago   110MB
mysql                       5.7              c20987f18b13   2 years ago   448MB
rabbitmq                    3.8-management   699038cb2b96   2 years ago   250MB
nacos/nacos-server          1.4.2            938169b118c7   2 years ago   956MB
redis                       5.0.9            987b553c835f   3 years ago   98.3MB
bladex/sentinel-dashboard   1.8.0            61c10eaefbcf   3 years ago   147MB
nacos/nacos-server          1.2.0            763941e566bb   3 years ago   732MB
bladex/sentinel-dashboard   1.7.1            d12e18546bfd   3 years ago   148MB
  1. REPOSITORY:镜像名称
  2. TAG:版本
  3. IMAGE ID:镜像 id
  4. CREATED:镜像创建的时间(官方创建此镜像的时间)
  5. SIZE:镜像大小

b)docker images -q 是用来查看所有镜像 id 的

[root@VM-8-17-centos ~]# docker images -q
c5da061a611a
c20987f18b13
699038cb2b96
938169b118c7
987b553c835f
61c10eaefbcf
763941e566bb
d12e18546bfd

Ps:一个镜像的 id 是很长的,这里只会展示一个部分

c)docker images 镜像名 用来查看指定镜像信息(镜像名相同,版本不同)

[root@VM-8-17-centos ~]# docker images redis
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
redis        5         c5da061a611a   2 years ago   110MB
redis        5.0.9     987b553c835f   3 years ago   98.3MB

同理,docker images -q 镜像名 就是展示指定镜像名的镜像id.

[root@VM-8-17-centos ~]# docker images -q redis
c5da061a611a
987b553c835f

下载镜像

用来下载一个镜像

docker pull 镜像名:版本号

a)例如下载最新版本 redis:docker pull redis 等同于 docker pull redis:latest

b)例如下载指定版本 redis:docker pull redis:5.0.9

搜索镜像

搜索镜像,只能查看远端仓库是否存在该镜像,不能列出版本.

docker search 镜像名

a)例如查看 tomcat 镜像是否存在

[root@VM-8-17-centos ~]# docker search tomcat
NAME                                  DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tomcat                                Apache Tomcat is an open source implementati…   3618      [OK]       
tomee                                 Apache TomEE is an all-Apache Java EE certif…   113       [OK]       
bitnami/tomcat                        Bitnami Tomcat Docker Image                     51                   [OK]
bitnamicharts/tomcat                                                                  0                    
secoresearch/tomcat-varnish           Tomcat and Varnish 5.0                          0                    [OK]
vulhub/tomcat                                                                         0                    
islandora/tomcat                                                                      0                    
wnprcehr/tomcat                                                                       0                    
jumpserver/tomcat                     Apache Tomcat is an open source implementati…   0                    
hivdb/tomcat-with-nucamino                                                            0                    
sismics/tomcat                        Apache Tomcat Servlet Container                 1                    
eclipse/rdf4j-workbench               Dockerfile for Eclipse RDF4J Server and Work…   6                    
eclipse/hadoop-dev                    Ubuntu 14.04, Maven 3.3.9, JDK8, Tomcat 8       0                    [OK]
gbif/ipt                              The GBIF Integrated Publishing Toolkit (IPT)…   2                    
dhis2/base-dev                        Images in this repository contains DHIS2 WAR…   0                    
eclipse/alpine_jdk8                   Based on Alpine 3.3. JDK 1.8, Maven 3.3.9, T…   1                    [OK]
dhis2/base                            Images in this repository contains DHIS2 WAR…   0                    
jelastic/tomcat                       An image of the Tomcat Java application serv…   4                    
cfje/tomcat-resource                  Tomcat Concourse Resource                       2                    
rightctrl/tomcat                      CentOS , Oracle Java, tomcat application ssl…   7                    [OK]
amd64/tomcat                          Apache Tomcat is an open source implementati…   8                    
arm64v8/tomcat                        Apache Tomcat is an open source implementati…   9                    
tomcat2111/papercut-mf                PaperCut MF Application Server                  0                    
softwareplant/tomcat                  Tomcat images for jira-cloud testing            0                    [OK]
tomcatengineering/pg_backup_rotated   Clone of martianrock/pg_backup_rotated but w…   0                    

删除镜像

删除指定镜像

docker image rm 镜像名(name:tag) | 镜像id

a)正常删除(要求:必须是没有正在运行的镜像),例如删除 tomcat:8.0 镜像

[root@VM-8-17-centos ~]# docker image rm tomcat:8.0
Untagged: tomcat:8.0
Untagged: tomcat@sha256:8ecb10948deb32c34aeadf7bf95d12a93fbd3527911fa629c1a3e7823b89ce6f
Deleted: sha256:ef6a7c98d192507d6066dcf24e44bec66d07ec9cf7c55d8d3d1ea0a24660bdef
Deleted: sha256:6dc5bbd9ede58ce52f6e9d34eaac4e3bf1fbb3014e9eae344677bf3c2f022a17
Deleted: sha256:6f22c12dcf0ac783b0b00471e38262c708761a677e6a847a57a5d7cce2cbc7f1
Deleted: sha256:dbefc7cd29b21d99c136d6234ca442cdb89fc91f3c91ef6c1d333d37424d2f44
Deleted: sha256:d65396dbf112285c9d395bb33c2eb2f776cd9b959c007152c10a2f25fbf1c198
Deleted: sha256:5b8a875f80bdd2e9f9cf2c0852243e0cb59ea7be5e92620b2c2089800bb18594
Deleted: sha256:d97b31b9ca51e024a895e2f6fa032224fb73ba2a070149499ce87306ed9d7af6
Deleted: sha256:3717c4f05493340d97d982bc6ed8cba98869833918de23c78c39414788dd08c1
Deleted: sha256:b9c326fb510188d2958888aee970ae93925c2a2ad8a78b2ec3a521747ee3ec4f
Deleted: sha256:8cc193ff8a5b4837eab54bee27418daadad8825f13b8fab55229b4954fee6f9f
Deleted: sha256:b1852f6f3f85863ed849af673e566ad8de76dac4d2c6526d791e965978c1ce62
Deleted: sha256:8c466bf4ca6ffdda8b7717b1cd6fe31109529ee64e626a003a224fb8bd2bc469

b)强制删除(可以删除正在运行的镜像):docker image rm -f 镜像名(name:tag) | 镜像 id

c)批量删除,例如删除所有 tomcat 镜像:docker image rm -f $(docker image tomcat -q)

容器命令

查看运行中的容器

查看运行中的容器信息

docker ps -a | -q

a)查看当前 docker 引擎中正在运行的容器

[root@VM-8-17-centos ~]# docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED       STATUS       PORTS                                                                                                                                                 NAMES
abc6284fe34d   redis:5.0.9                "docker-entrypoint.s…"   5 weeks ago   Up 5 weeks   0.0.0.0:6380->6379/tcp, :::6380->6379/tcp                                                                                                             redis
d442ff7829df   nacos/nacos-server:1.4.2   "bin/docker-startup.…"   6 weeks ago   Up 5 weeks   0.0.0.0:8848->8848/tcp, :::8848->8848/tcp                                                                                                             nacos
fc16ae62dc0f   mysql:5.7                  "docker-entrypoint.s…"   7 weeks ago   Up 7 weeks   33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp                                                                                                  mysql
a7dbf979b1e6   rabbitmq:3.8-management    "docker-entrypoint.s…"   7 weeks ago   Up 7 weeks   4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp   mq
  • CONTAINER ID:容器 id
  • IMAGE:基于那个镜像运行的
  • COMMAND:容器内启动服务的命令
  • CREATED:容器创建时间
  • STATUS:容器状态
  • PORTS:容器服务监听端口("->" 前表示宿主机端口,"->" 后表示映射的容器端口)
  • NAMES:容器名称(启动时,通过 --name 参数自定义的)

b)查看所有容器(运行 和 停止 的容器):docker ps -a

c)查看所有容器id:docker ps -aq

运行容器

docker run -d(后台运行) -p(端口映射) --name 自定义容器名 镜像名:tag

以下拿 tomcat:8.0 来举例 

a)简单运行一个容器(这种方式运行容器,会导致容器内无法访问,因为这里涉及到容器端口映射的概念,后面会讲)

[root@VM-8-17-centos ~]# docker run tomcat:8.0
23-Dec-2023 12:25:27.847 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.53
23-Dec-2023 12:25:27.849 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 29 2018 14:42:45 UTC
23-Dec-2023 12:25:27.849 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.53.0
23-Dec-2023 12:25:27.849 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
23-Dec-2023 12:25:27.849 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-1160.99.1.el7.x86_64
23-Dec-2023 12:25:27.849 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
23-Dec-2023 12:25:27.849 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-7-openjdk-amd64/jre
23-Dec-2023 12:25:27.849 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.7.0_181-b01
23-Dec-2023 12:25:27.850 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
23-Dec-2023 12:25:27.850 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
23-Dec-2023 12:25:27.850 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
23-Dec-2023 12:25:27.851 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
23-Dec-2023 12:25:27.851 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
23-Dec-2023 12:25:27.851 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
23-Dec-2023 12:25:27.851 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
23-Dec-2023 12:25:27.851 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
23-Dec-2023 12:25:27.851 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
23-Dec-2023 12:25:27.851 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
23-Dec-2023 12:25:27.851 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
23-Dec-2023 12:25:27.852 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.17 using APR version 1.5.1.
23-Dec-2023 12:25:27.852 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
23-Dec-2023 12:25:27.855 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.1.0f  25 May 2017)
23-Dec-2023 12:25:28.071 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
23-Dec-2023 12:25:28.083 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
23-Dec-2023 12:25:28.086 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 951 ms
23-Dec-2023 12:25:28.147 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
23-Dec-2023 12:25:28.148 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.53
23-Dec-2023 12:25:28.163 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
23-Dec-2023 12:25:28.827 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 663 ms
23-Dec-2023 12:25:28.827 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
23-Dec-2023 12:25:29.319 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 492 ms
23-Dec-2023 12:25:29.319 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
23-Dec-2023 12:25:29.379 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 60 ms
23-Dec-2023 12:25:29.379 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
23-Dec-2023 12:25:29.439 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 60 ms
23-Dec-2023 12:25:29.439 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT
23-Dec-2023 12:25:29.468 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 29 ms
23-Dec-2023 12:25:29.486 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
23-Dec-2023 12:25:29.550 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
23-Dec-2023 12:25:29.554 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1467 ms

b)运行 tomcat 容器,设置容器与宿主机端口映射关系

docker run -p 8081:8080 tomcat:8.0

Ps:-p 8081(宿主机):8080(容器)

c)运行 tomcat 容器,设置设置容器与宿主机端口映射关系,后台启动服务

docker run -p 8081:8080 -d tomcat:8.0

d)运行 tomcat 容器,设置设置容器与宿主机端口映射关系,后台启动服务,自定义容器名称

docker run -p 8081:8080 -d --name tomcat_1 tomcat:8.0

停止、启动、重启、暂停、恢复容器

停止容器:docker stop 容器id | name(这里的 name 是启动时自定义的)

启动容器:docker start 容器 id | name

重启容器:docker restart 容器 id | name

暂停容器:docker pause 容器 id | name

恢复容器(从暂停恢复到启动):docker unpause 容器 id | name

杀死容器

docker kill id | name

例如删除名称为 tomcat_1 的容器 

[root@VM-8-17-centos ~]# docker kill tomcat_1
tomcat_1

删除容器

a)正常删除容器(只能删除已经停止的容器):docker rm id | name

b)强制删除容器(可以删除运行中的容器):docker rm -f id | name

c)批量删除容器:docker rm -f $(docker ps -qa)

查看容器日志

docker logs -f id | name

a)查看当前容器的日志信息,例如查看 tomcat_1 容器的日志

[root@VM-8-17-centos ~]# docker logs tomcat_1
23-Dec-2023 12:50:00.505 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.53
23-Dec-2023 12:50:00.508 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 29 2018 14:42:45 UTC
23-Dec-2023 12:50:00.508 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.0.53.0
23-Dec-2023 12:50:00.508 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
23-Dec-2023 12:50:00.508 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-1160.99.1.el7.x86_64
23-Dec-2023 12:50:00.509 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
23-Dec-2023 12:50:00.509 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-7-openjdk-amd64/jre
23-Dec-2023 12:50:00.509 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.7.0_181-b01
23-Dec-2023 12:50:00.509 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
23-Dec-2023 12:50:00.509 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
23-Dec-2023 12:50:00.509 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
23-Dec-2023 12:50:00.510 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
23-Dec-2023 12:50:00.510 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
23-Dec-2023 12:50:00.510 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
23-Dec-2023 12:50:00.510 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
23-Dec-2023 12:50:00.510 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
23-Dec-2023 12:50:00.510 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
23-Dec-2023 12:50:00.510 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
23-Dec-2023 12:50:00.510 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
23-Dec-2023 12:50:00.511 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.17 using APR version 1.5.1.
23-Dec-2023 12:50:00.511 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
23-Dec-2023 12:50:00.515 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.1.0f  25 May 2017)
23-Dec-2023 12:50:00.712 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
23-Dec-2023 12:50:00.724 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
23-Dec-2023 12:50:00.726 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 920 ms
23-Dec-2023 12:50:00.780 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
23-Dec-2023 12:50:00.780 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.53
23-Dec-2023 12:50:00.795 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
23-Dec-2023 12:50:01.435 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 639 ms
23-Dec-2023 12:50:01.435 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
23-Dec-2023 12:50:01.931 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 496 ms
23-Dec-2023 12:50:01.931 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
23-Dec-2023 12:50:02.001 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 70 ms
23-Dec-2023 12:50:02.002 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
23-Dec-2023 12:50:02.075 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 73 ms
23-Dec-2023 12:50:02.075 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT
23-Dec-2023 12:50:02.108 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 33 ms
23-Dec-2023 12:50:02.118 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
23-Dec-2023 12:50:02.152 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
23-Dec-2023 12:50:02.155 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1429 ms

b)通过 -f 实时监控容器内服务的日志:docker logs -f id | name

进入容器内部

docker exec -it(交互模式) id | name bash

a)例如进入 tomcat_1 容器内部,然后查看容器内部的文件

[root@VM-8-17-centos ~]# docker exec -it tomcat_1 bash
root@e823da882acc:/usr/local/tomcat# ls
LICENSE  NOTICE  RELEASE-NOTES	RUNNING.txt  bin  conf	include  lib  logs  native-jni-lib  temp  webapps  work

b)退出容器:exit

root@e823da882acc:/usr/local/tomcat# exit
exit
[root@VM-8-17-centos ~]# 

容器与宿主机之间的文件拷贝

a)将容器中指定文件拷贝到宿主机:docker cp 容器id:容器中文件或目录 宿主机目录

例如将 tomcat 容器中的 /usr/local/tomcat/RUNNING.txt 文件拷贝到宿主机的 /root/cyk/ 目录下

[root@VM-8-17-centos cyk]# docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS          PORTS                                                                                                                                                 NAMES
e823da882acc   tomcat:8.0                 "catalina.sh run"        11 minutes ago   Up 11 minutes   0.0.0.0:8082->8080/tcp, :::8082->8080/tcp                                                                                                             tomcat_1
abc6284fe34d   redis:5.0.9                "docker-entrypoint.s…"   5 weeks ago      Up 5 weeks      0.0.0.0:6380->6379/tcp, :::6380->6379/tcp                                                                                                             redis
d442ff7829df   nacos/nacos-server:1.4.2   "bin/docker-startup.…"   6 weeks ago      Up 5 weeks      0.0.0.0:8848->8848/tcp, :::8848->8848/tcp                                                                                                             nacos
fc16ae62dc0f   mysql:5.7                  "docker-entrypoint.s…"   7 weeks ago      Up 7 weeks      33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp                                                                                                  mysql
a7dbf979b1e6   rabbitmq:3.8-management    "docker-entrypoint.s…"   7 weeks ago      Up 7 weeks      4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp   mq
[root@VM-8-17-centos cyk]# 
[root@VM-8-17-centos cyk]# docker cp e8:/usr/local/tomcat/RUNNING.txt /root/cyk/
Successfully copied 17.9kB to /root/cyk/
[root@VM-8-17-centos cyk]# ls
RUNNING.txt

Ps:这里的 e8 是 tomcat_1 容器 id 的简写,只要能区分开,怎么简写都可以

b)将宿主机中指定文件拷贝到容器内:docker cp 宿主机目录 容器id:容器中文件或目录

如何部署一个 web 项目(war 包项目)

a)将 xxx.war 上传到 linux 服务器

b)通过 docker cp 命令将 xxx.war 赋值到 tomcat 的 webapp 目录中即可.

c)使用 ip 端口进行测试访问即可.

查看容器内运行的进程信息

docker top 容器id | name

a)查看 tomcat_1 容器内运行的进程信息

[root@VM-8-17-centos cyk]# docker top tomcat_1
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                32112               32092               0                   20:49               ?                   00:00:05            /docker-java-home/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start

查看容器内部细节

docker inspect 容器id | name

a)例如查看 tomcat_1 容器内部细节 

[root@VM-8-17-centos cyk]# docker inspect tomcat_1
[{"Id": "e823da882accc99496e297da6cbf0004e3b1033304f65d6a2d3e538a36d53665","Created": "2023-12-23T12:49:58.845311366Z","Path": "catalina.sh","Args": ["run"],"State": {"Status": "running","Running": true,"Paused": false,"Restarting": false,"OOMKilled": false,"Dead": false,"Pid": 32112,"ExitCode": 0,"Error": "","StartedAt": "2023-12-23T12:49:59.234928823Z","FinishedAt": "0001-01-01T00:00:00Z"},"Image": "sha256:ef6a7c98d192507d6066dcf24e44bec66d07ec9cf7c55d8d3d1ea0a24660bdef","ResolvConfPath": "/var/lib/docker/containers/e823da882accc99496e297da6cbf0004e3b1033304f65d6a2d3e538a36d53665/resolv.conf","HostnamePath": "/var/lib/docker/containers/e823da882accc99496e297da6cbf0004e3b1033304f65d6a2d3e538a36d53665/hostname","HostsPath": "/var/lib/docker/containers/e823da882accc99496e297da6cbf0004e3b1033304f65d6a2d3e538a36d53665/hosts","LogPath": "/var/lib/docker/containers/e823da882accc99496e297da6cbf0004e3b1033304f65d6a2d3e538a36d53665/e823da882accc99496e297da6cbf0004e3b1033304f65d6a2d3e538a36d53665-json.log","Name": "/tomcat_1","RestartCount": 0,"Driver": "overlay2","Platform": "linux","MountLabel": "","ProcessLabel": "","AppArmorProfile": "","ExecIDs": null,"HostConfig": {"Binds": null,"ContainerIDFile": "","LogConfig": {"Type": "json-file","Config": {}},"NetworkMode": "default","PortBindings": {"8080/tcp": [{"HostIp": "","HostPort": "8082"}]},"RestartPolicy": {"Name": "no","MaximumRetryCount": 0},"AutoRemove": false,"VolumeDriver": "","VolumesFrom": null,"ConsoleSize": [36,171],"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","Isolation": "","CpuShares": 0,"Memory": 0,"NanoCpus": 0,"CgroupParent": "","BlkioWeight": 0,"BlkioWeightDevice": [],"BlkioDeviceReadBps": [],"BlkioDeviceWriteBps": [],"BlkioDeviceReadIOps": [],"BlkioDeviceWriteIOps": [],"CpuPeriod": 0,"CpuQuota": 0,"CpuRealtimePeriod": 0,"CpuRealtimeRuntime": 0,"CpusetCpus": "","CpusetMems": "","Devices": [],"DeviceCgroupRules": null,"DeviceRequests": null,"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","/sys/devices/virtual/powercap"],"ReadonlyPaths": ["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]},"GraphDriver": {"Data": {"LowerDir": "/var/lib/docker/overlay2/1807f8589086eb51f861c4938ddbd1da9395c48ef3b1bc40ded35195707c07db-init/diff:/var/lib/docker/overlay2/4272a408897873c3e991cc410cc9f3191dc2ebb5a8f940e386746a8b62e45b77/diff:/var/lib/docker/overlay2/aefe736cf7883ec152540cf245eebf8d1daee7ebd7752db0f2aed440db9c436e/diff:/var/lib/docker/overlay2/eab8218d1796d5eaa07da26ded1c78c01b0d7dfaf96654c7223f94fa022804ca/diff:/var/lib/docker/overlay2/6a1ae79728973f2f3dde69c44b8bf36c7e3e8dee18a67777f2c18298c27b72e3/diff:/var/lib/docker/overlay2/4284addc9df80d1ca1f05dddd850dd749c9cc55c34f28b0876d5eaacc2d576e5/diff:/var/lib/docker/overlay2/ed77212064855a9fee7e0403c15a23667de8c08fe7d59635f328c1b91e8e0af1/diff:/var/lib/docker/overlay2/1e0a0cebf48bf83030ebecda040939bc9eb11094883fa716bde5789cfc8d5ed1/diff:/var/lib/docker/overlay2/648a8998071f0296333f194e322e6785fb01b763e684543c6d665eb74965567b/diff:/var/lib/docker/overlay2/96aaa73c0076e21994ad88907d5f425ebf630fab7e091eb301073b4429c2f609/diff:/var/lib/docker/overlay2/6315239813db62569e9e729bbf20f7d6220df8a170fbd4fae2e1eba015e4f51d/diff:/var/lib/docker/overlay2/6951fbc42d9b579b84c403fdb31421d105aac328ad81e2e3e1d55a11556afcf7/diff","MergedDir": "/var/lib/docker/overlay2/1807f8589086eb51f861c4938ddbd1da9395c48ef3b1bc40ded35195707c07db/merged","UpperDir": "/var/lib/docker/overlay2/1807f8589086eb51f861c4938ddbd1da9395c48ef3b1bc40ded35195707c07db/diff","WorkDir": "/var/lib/docker/overlay2/1807f8589086eb51f861c4938ddbd1da9395c48ef3b1bc40ded35195707c07db/work"},"Name": "overlay2"},"Mounts": [],"Config": {"Hostname": "e823da882acc","Domainname": "","User": "","AttachStdin": false,"AttachStdout": false,"AttachStderr": false,"ExposedPorts": {"8080/tcp": {}},"Tty": false,"OpenStdin": false,"StdinOnce": false,"Env": ["PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JAVA_HOME=/docker-java-home/jre","JAVA_VERSION=7u181","JAVA_DEBIAN_VERSION=7u181-2.6.14-1~deb8u1","CATALINA_HOME=/usr/local/tomcat","TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib","LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib","OPENSSL_VERSION=1.1.0f-3+deb9u2","GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23","TOMCAT_MAJOR=8","TOMCAT_VERSION=8.0.53","TOMCAT_SHA512=cd8a4e48a629a2f2bb4ce6b101ebcce41da52b506064396ec1b2915c0b0d8d82123091242f2929a649bcd8b65ecf6cd1ab9c7d90ac0e261821097ab6fbe22df9","TOMCAT_TGZ_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://www.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz \thttps://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz","TOMCAT_ASC_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://www.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc \thttps://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz.asc"],"Cmd": ["catalina.sh","run"],"Image": "tomcat:8.0","Volumes": null,"WorkingDir": "/usr/local/tomcat","Entrypoint": null,"OnBuild": null,"Labels": {}},"NetworkSettings": {"Bridge": "","SandboxID": "7c5c3740d5acbd7748c07d0203d0833f72ebb617c7b3d0e76a3e6d8a2510e062","HairpinMode": false,"LinkLocalIPv6Address": "","LinkLocalIPv6PrefixLen": 0,"Ports": {"8080/tcp": [{"HostIp": "0.0.0.0","HostPort": "8082"},{"HostIp": "::","HostPort": "8082"}]},"SandboxKey": "/var/run/docker/netns/7c5c3740d5ac","SecondaryIPAddresses": null,"SecondaryIPv6Addresses": null,"EndpointID": "2294463d89e7a91ee32cbd717403ceb9d1079fc23fca9cd251c003fa019bff0c","Gateway": "172.17.0.1","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"IPAddress": "172.17.0.6","IPPrefixLen": 16,"IPv6Gateway": "","MacAddress": "02:42:ac:11:00:06","Networks": {"bridge": {"IPAMConfig": null,"Links": null,"Aliases": null,"NetworkID": "3be1ce6eea6f4f139c964c6afa94dd46fa60576e291edbc56d730c3c977b018c","EndpointID": "2294463d89e7a91ee32cbd717403ceb9d1079fc23fca9cd251c003fa019bff0c","Gateway": "172.17.0.1","IPAddress": "172.17.0.6","IPPrefixLen": 16,"IPv6Gateway": "","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"MacAddress": "02:42:ac:11:00:06","DriverOpts": null}}}}
]

数据卷

作用&使用场景&注意事项

a)主要作用:

用来实现容器中数据和宿主机中数据进行映射的(这里可以类比 Vue 中的双向绑定,修改任意一方,另一方都会跟着修改)

b)使用场景:

  1. 易修改:即使我们不进入容器的内部,也可以通过修改宿主机文件系统的 conf 文件,来修改容器中的 conf 文件;
  2. 数据可复用:当创建了新的容器并且需要复用之前的 conf 文件时,可以直接再创建一个数据卷或者修改之前数据卷对容器目录的指向即可,来进行关联,这样就可以将之前的配置映射到新容器的配置中;
  3. 升级维护简单:如果来了新的容器,需要删除旧容器,也不用担心数据会被删除掉,因为数据在宿主机上还保存了一份。

c)注意事项:数据卷只能在容器首次启动时设置.

容器启动时指定数据卷

容器首次启动时指定 -v 参数

a)使用绝对路径设置数据卷

docker run -v 宿主机绝对路径:容器内绝对路径:ro .....(其他设置)

ro:表示 ready only,也就是只读的意思,如果在设置数据卷时指定 ro,代表日后从容器内访问该路径时是只读的.

Ps:这种方式会将容器该路径下的原始内容全部清空,始终以宿主机路径为主.

b)使用别名方式设置数据卷

docker run -v aa:/usr/local/tomcat/webapps ......(其他配置)

aa:

  1. 别名就代表一个 docker 自身维护的数据卷
  2. aa 代表 docker 数据卷中别名. (如果存在就直接使用,不存在就创建)
  3. 使用别名方式保留容器路径原始内容,前提是别名对应路径不能存在内容.

Ps:docker 根据别名创建目录默认在 /var/lib/docker/volumes/ 中.

通过 find 命令也可以查找到该路径

 

查看 docker 所有数据卷

通过 docker volume ls 即可查看

如下

[root@VM-8-17-centos ~]# docker volume ls
DRIVER    VOLUME NAME
local     1fa61b3ede8d2275b627925fb6c9270d0ce90cf802297a442cba63cac2bd8318
local     5ea35e4af2de3e83feb7a290ad28cbb1efcea43f7fc239a24083a33dd358ee7d
local     6d9ce8b53920cc2e57b15c6828e64055edffda6ecc8c70d51e3dbe720ae7525c
local     6e7cdbf67ca74fd270fa99c64ac5e7a0608d419c68b35f1159918365f430ada4
local     9b4f364313d3b30f69e9ef0cd33f023939ddf7b3477fe8d59957be15bf35116a
local     25c87a7dccf3b2d8a72592c928e802edfec4243ec276442fa4d7045c65a95d7a
local     37b3dbb78b118db577912d599c9b18b5f3de38519a74fd6f14b7a90a7e4a6ed7
local     53b0ba745b895e113d38b7adea5775122e7468722d3c7050b8209166ef730608
local     70b2e875c2ad077202f8e9d3503cc4e2ad48b119b5150ef47cfa98e6b713c1b2
local     91e437d40a873ed676500c8c574c3bcfd7081ce3a800f0d15f9c89ee2c507ba4
local     126a034b14738aa704b485b57d6146af54aa8c8778fc9645edf94b9cd979b651
local     322c7e1b4e8c21fef177655444afe1a87e478a175502d2c5fa2223c22bd7c212
local     3639cf3d08c4e838c675b026e572832b6cd2c7d75cb6052635374a2266a09b18
local     7810b502a8c2334df68de79a88b4fb096c4c77d88380346022f26a83e830513f
local     9362e057c7d64db8887a1da36089b053bebdd473a1b4213f7b3afa45fd1c5070
local     41589e0d737e2b6794904e4630a621618c99e86d171230b7718a2c505f38fd1c
local     176090d6b2c68af41962863317d97e912be5ca4b8917158db49ad549ad6f4561
local     380554b41086565ff8e677f7de48e7fd4565bd28b4c193b4e859c20bef16e5c7
local     651871ea674decee5310c1f80da30136df924cf46e377b595c8e2af3a280b162
local     46888212f86c0ad196e798d3d9d77ca1c5b91ce55b2055dca13e1a8d07e7f7b7
local     048558136abb49fbb611aecacb9080ad7cb931f9b4ac1e29b350a81572f507a8
local     a6e06baf59e0a30eb6a09cab7cebffc0500ebcfdad86a728fd4d68f98cce33fb
local     a81e39eb18b192822d177c48734c2d3cd7b52c1b1e9d19864438a13d83ec2288
local     aca12e56a6ffe71e33e46fd12c93aa0fc12abdc90a9f3778883d68a4b16e7633
local     c5c137ece3e1f8e210f75cc3141a2422a65de832111e3505f5ad0189f265088b
local     d50c81b40c2cd31f267e894048aa907b68e336cc0d9b74060112ffc30e67b4d0
local     e21898073e75de299a86adef3a8b2d9ed577a36aa3c5771d8f8d33de4cbb8ba4
local     ebd4d620e209c9062a5e6f9058d574e0a74e4554b1af108f7ffa1dc4d9f6ecb8
local     ecc0c22ac9231a32c7361cc6e2c81b9239a34e86e2c14fc60b01a5dea778658e
local     f2e477434d0dfe055b3cb1e8b7f998ea243d4001c7e10cfa0b81603673b51da3
local     f49c6495220342f9d587f1ac7653ddca92a7c43737dea8178cc8a3165514d974

创建一个别名数据卷

docker volume create 数据卷别名

例如创建数据卷别名为 aa,然后查看列表

[root@VM-8-17-centos ~]# docker volume create aaa
aaa
[root@VM-8-17-centos ~]# docker volume ls
DRIVER    VOLUME NAME
local     1fa61b3ede8d2275b627925fb6c9270d0ce90cf802297a442cba63cac2bd8318
local     5ea35e4af2de3e83feb7a290ad28cbb1efcea43f7fc239a24083a33dd358ee7d
local     6d9ce8b53920cc2e57b15c6828e64055edffda6ecc8c70d51e3dbe720ae7525c
local     6e7cdbf67ca74fd270fa99c64ac5e7a0608d419c68b35f1159918365f430ada4
local     9b4f364313d3b30f69e9ef0cd33f023939ddf7b3477fe8d59957be15bf35116a
local     25c87a7dccf3b2d8a72592c928e802edfec4243ec276442fa4d7045c65a95d7a
local     37b3dbb78b118db577912d599c9b18b5f3de38519a74fd6f14b7a90a7e4a6ed7
local     53b0ba745b895e113d38b7adea5775122e7468722d3c7050b8209166ef730608
local     70b2e875c2ad077202f8e9d3503cc4e2ad48b119b5150ef47cfa98e6b713c1b2
local     91e437d40a873ed676500c8c574c3bcfd7081ce3a800f0d15f9c89ee2c507ba4
local     126a034b14738aa704b485b57d6146af54aa8c8778fc9645edf94b9cd979b651
local     322c7e1b4e8c21fef177655444afe1a87e478a175502d2c5fa2223c22bd7c212
local     3639cf3d08c4e838c675b026e572832b6cd2c7d75cb6052635374a2266a09b18
local     7810b502a8c2334df68de79a88b4fb096c4c77d88380346022f26a83e830513f
local     9362e057c7d64db8887a1da36089b053bebdd473a1b4213f7b3afa45fd1c5070
local     41589e0d737e2b6794904e4630a621618c99e86d171230b7718a2c505f38fd1c
local     176090d6b2c68af41962863317d97e912be5ca4b8917158db49ad549ad6f4561
local     380554b41086565ff8e677f7de48e7fd4565bd28b4c193b4e859c20bef16e5c7
local     651871ea674decee5310c1f80da30136df924cf46e377b595c8e2af3a280b162
local     46888212f86c0ad196e798d3d9d77ca1c5b91ce55b2055dca13e1a8d07e7f7b7
local     048558136abb49fbb611aecacb9080ad7cb931f9b4ac1e29b350a81572f507a8
local     a6e06baf59e0a30eb6a09cab7cebffc0500ebcfdad86a728fd4d68f98cce33fb
local     a81e39eb18b192822d177c48734c2d3cd7b52c1b1e9d19864438a13d83ec2288
local     aaa
local     aca12e56a6ffe71e33e46fd12c93aa0fc12abdc90a9f3778883d68a4b16e7633
local     c5c137ece3e1f8e210f75cc3141a2422a65de832111e3505f5ad0189f265088b
local     d50c81b40c2cd31f267e894048aa907b68e336cc0d9b74060112ffc30e67b4d0
local     e21898073e75de299a86adef3a8b2d9ed577a36aa3c5771d8f8d33de4cbb8ba4
local     ebd4d620e209c9062a5e6f9058d574e0a74e4554b1af108f7ffa1dc4d9f6ecb8
local     ecc0c22ac9231a32c7361cc6e2c81b9239a34e86e2c14fc60b01a5dea778658e
local     f2e477434d0dfe055b3cb1e8b7f998ea243d4001c7e10cfa0b81603673b51da3
local     f49c6495220342f9d587f1ac7653ddca92a7c43737dea8178cc8a3165514d974

查看数据卷详细内容

数据卷详细信息中就包含了数据卷的在宿主机的绝对路径

docker volume inspect 数据卷别名

例如查看别名 aaa 的详细信息 

[root@VM-8-17-centos ~]# docker volume inspect aaa
[{"CreatedAt": "2023-12-27T15:54:07+08:00","Driver": "local","Labels": null,"Mountpoint": "/var/lib/docker/volumes/aaa/_data","Name": "aaa","Options": null,"Scope": "local"}
]

Ps:Mountpoint 就是在宿主机的绝对路径

删除一个数据卷

docker volume rm 数据卷别名

 例如删除别名为 aaa 的数据卷

[root@VM-8-17-centos ~]# docker volume rm aaa
aaa

容器打包镜像

背景

a)回顾三个核心概念

仓库 repository:docker 官方维护的一个仓库,用来集中存储镜像.

镜像 image:一个镜像代表一个软件服务,特点就是 "只读".

容器 container:镜像每运行一次形成一个容器,运行的容器代表一个正在运行的软件服务.

b)为什么要将容器打包成一个新的镜像?

容器可读可写,那么基于这个特性就可以对容器进行自己的深度定制.

将容器打包成一个新的镜像,日后运行的这个容器就存在原始定制的特性.

c)原理图

将容器打包成一个新的镜像

docker commit -m "对镜像的描述" -a "作者名称" 容器id | name  镜像名:版本

如下案例

[root@VM-8-17-centos cyk]# docker ps -a
CONTAINER ID   IMAGE                      COMMAND                  CREATED             STATUS                           PORTS                                                                                                                                                 NAMES
e823da882acc   tomcat:8.0                 "catalina.sh run"        About an hour ago   Up About an hour                 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp                                                                                                             tomcat_1
07a1f69b4c4c   tomcat:8.0                 "catalina.sh run"        About an hour ago   Exited (137) About an hour ago                                                                                                                                                         objective_taussig
abc6284fe34d   redis:5.0.9                "docker-entrypoint.s…"   5 weeks ago         Up 5 weeks                       0.0.0.0:6380->6379/tcp, :::6380->6379/tcp                                                                                                             redis
d442ff7829df   nacos/nacos-server:1.4.2   "bin/docker-startup.…"   6 weeks ago         Up 5 weeks                       0.0.0.0:8848->8848/tcp, :::8848->8848/tcp                                                                                                             nacos
fc16ae62dc0f   mysql:5.7                  "docker-entrypoint.s…"   7 weeks ago         Up 7 weeks                       33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp                                                                                                  mysql
a7dbf979b1e6   rabbitmq:3.8-management    "docker-entrypoint.s…"   7 weeks ago         Up 7 weeks                       4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp   mq
[root@VM-8-17-centos cyk]# 
[root@VM-8-17-centos cyk]# 
[root@VM-8-17-centos cyk]# 
[root@VM-8-17-centos cyk]# docker commit -m "new test tomcat" -a "cyk" e8 tomcat_cyk:8.1
sha256:9b9add65a1f1b2a9331bac5f0c047af6a921e0850b247638256843a770b4ed6d
[root@VM-8-17-centos cyk]# docker images
REPOSITORY                  TAG              IMAGE ID       CREATED          SIZE
tomcat_cyk                  8.1              9b9add65a1f1   10 seconds ago   356MB
redis                       5                c5da061a611a   2 years ago      110MB
mysql                       5.7              c20987f18b13   2 years ago      448MB
rabbitmq                    3.8-management   699038cb2b96   2 years ago      250MB
nacos/nacos-server          1.4.2            938169b118c7   2 years ago      956MB
redis                       5.0.9            987b553c835f   3 years ago      98.3MB
bladex/sentinel-dashboard   1.8.0            61c10eaefbcf   3 years ago      147MB
nacos/nacos-server          1.2.0            763941e566bb   3 years ago      732MB
bladex/sentinel-dashboard   1.7.1            d12e18546bfd   3 years ago      148MB
tomcat                      8.0              ef6a7c98d192   5 years ago      356MB

镜像的备份和恢复

a)备份镜像: docker save 镜像名:tag -o (镜像名-tag).tar

b)恢复镜像:docker load -i xxx.tar

例如 docker load -i tomcat-8.0.tar 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/580664.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

软件测试/测试开发丨Pytest学习笔记

Pytest 格式要求 文件: 以 test_ 开头或以 _test 结尾类: 以 Test 开头方法/函数: 以 _test 开头测试类中不可以添加构造函数, 若添加构造函数将导致Pytest无法识别类下的测试方法 断言 与Unittest不同, 在Pytest中我们需要使用python自带的 assert 关键字进行断言 assert…

中介者模式-Mediator Pattern-1

如果在一个系统中对象之间的联系呈现为网状结构, 对象之间存在大量的多对多联系,将导致系统非常复杂。 这些对象既会影响别的对象,也会被别的对象所影响。 这些对象称为同事对象,它们之间通过彼此的相互作用实现系统的行为。 在网…

找不到msvcp140.dll怎么办-msvcp140.dll丢失的解决方法分享

在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是“msvcp140.dll丢失”。那么,msvcp140.dll究竟是什么文件?为什么会出现丢失的情况?本文将详细介绍msvcp140.dll的属性、作用以及丢失的原因,并…

Java学习笔记(八)——面向对象编程(高级)

目录 一、类变量和类方法 (一)类变量/静态变量 类变量内存布局 类变量使用注意事项和细节 (二)类方法 类方法经典的使用场景 类方法使用注意事项和细节 二、理解main方法语法 三、代码块 代码块使用注意事项和细节 四、…

Graylog日志搜索技巧

graylog搜索日志用的语法是Syntax接近Lucene,搜起来比较方便 Search query languagehttps://go2docs.graylog.org/4-0/making_sense_of_your_log_data/writing_search_queries.html?tocpathSearching%20Your%20Log%20Data|_____1 1.Syntax 语法 1.1 基本匹配 搜…

java keytool.exe ssl

JDK如果没有先安装 JDK8 install_jdk aleady install-CSDN博客 java keytool.exe ssl keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore D:\server.keystore -validity 3650 server.ssl.key-storeD:\server.keystore server.ssl.key-…

怎么使用jupter notebook并配置环境变量

有的时候需要使用Jupyter Notebook运行代码,Jupyter Notebook的主要特点: ① 编程时具有语法高亮、缩进、tab补全的功能。 ② 可直接通过浏览器运行代码,同时在代码块下方展示运行结果。 ③ 以富媒体格式展示计算结果。富媒体格式包括&…

linux ubuntu常用命令大总结(1)

假设:在/home/test文件夹下有一个a.py文件 清屏 clear 文件和目录操作: clear: 清屏 clearls: 列出 /home/test 目录中的文件和子目录。 ls ls /home/testcd: 切换到 /home/test 目录。 cd cd /home/testpwd: 显示当前工作目录的路径。 pwdtouch:…

IPv4 VS IPv6代理全解,跨境电商代理IP选哪种?

IP(互联网协议)被网站用来收集用户位置信息。当今最流行的两种互联网协议是 IPv4 和 IPv6。 在我们选择IP代理的过程中可以看到IPv4、IPv6两种类型,他们有何区别?如何选择?下面为大家讲解! 在这篇文章中&a…

数据库开发之子查询的详细解析

1.4 子查询 1.4.1 介绍 SQL语句中嵌套select语句,称为嵌套查询,又称子查询。 SELECT * FROM t1 WHERE column1 ( SELECT column1 FROM t2 ... ); 子查询外部的语句可以是insert / update / delete / select 的任何一个,最常见…

【JavaScript】Set、Map、WeakSet、WeakMap

✨ 专栏介绍 在现代Web开发中,JavaScript已经成为了不可或缺的一部分。它不仅可以为网页增加交互性和动态性,还可以在后端开发中使用Node.js构建高效的服务器端应用程序。作为一种灵活且易学的脚本语言,JavaScript具有广泛的应用场景&#x…

数据治理认证大揭秘:CDMP、CDGA与CDGP,你了解多少?

IT码农们,你们是否经常被问到关于数据治理认证CDMP、CDGA和CDGP的问题?今天就来给大家好好科普一下! 🔮 CDMP:数据治理的基石 CDMP,即数据管理专业人士认证,是迈向数据治理旅程的起点。它为你打…

分享七种msvcp140.dll丢失的解决方法,帮助大家解决msvcp140.dll丢失

msvcp140.dll是一个重要的系统文件,它是微软视觉C可再发行包的一部分。这个动态链接库(DLL)文件对于运行那些用Visual Studio 2015及其更新版本开发的应用程序至关重要。在Windows操作系统中,DLL文件提供执行许多常见任务的必要指…

【回溯】装载问题Python实现

文章目录 [toc]问题描述问题转换回溯法时间复杂性Python实现 个人主页:丷从心 系列专栏:回溯法 问题描述 有一批共 n n n个集装箱要装上 2 2 2艘载重量分别为 c 1 c_{1} c1​和 c 2 c_{2} c2​的轮船,其中集装箱 i i i的重量为 w i w_{i} w…

async和await的使用

async和await是promise的一种语法糖,也就是更简单易懂的写法。 在很多项目中,你会经常看到async和await的配合使用,看到原始的promise写法反而不多,就是因为async-await这种写法是用同步的语法去实现异步的逻辑。 基础使用 原生promise写法 let value nulllet proFn new P…

AR智慧校园三维主电子沙盘系统研究及应用

一 、概述 易图讯科技(www.3dgis.top)自主研发的智慧校园三维主电子沙盘系统,采用B/S架构模式,采用自主可控高性能WebGIS可视化引擎,支持多用户客户端通过网络请求访问服务器地图和专题数据,提供地理信息数据、专题数据的并发访问…

Temu和Shein争端再起:海外电商“围城”下,一场厮杀正在酝酿

两家中国电商出海“双子星”,争端再起。 最近,美国法院最新公开临时限制令显示,跨境电商平台Temu(特木)的男装、休闲装、运动服等50款产品涉侵权时尚电商平台Shein(希音),并向Temu旗…

智能优化算法应用:基于蜣螂算法3D无线传感器网络(WSN)覆盖优化 - 附代码

智能优化算法应用:基于蜣螂算法3D无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用:基于蜣螂算法3D无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.蜣螂算法4.实验参数设定5.算法结果6.参考文献7.MA…

十二.视图

视图 1.常见数据库对象2.视图概述2.1为什么使用视图2.2视图的理解 3.创建视图3.1创建单表视图3.2创建多表联合试图3.3基于试图创建视图 4.查看视图5.更新视图的数据5.1一般情况5.2不可更新的视图 6.修改、删除视图6.1修改视图6.2删除视图 7.总结7.1视图优点7.2视图不足 1.常见数…

【C语言:编译、预处理详解】

文章目录 1.编译2.预处理2.1宏定义2.1.1预定义符号2.1.2#define定义常量2.1.3#define定义宏2.1.4do-while-zero2.1.5宏的注意事项2.1.6宏与函数的对比 2.2条件编译2.3文件包含 3.offsetoff4.#与##4.1. #号4.2 ##号 1.编译 我们都知道,一个程序如果想运行起来要经过…