三、Docker的常用命令

三、Docker的常用命令

一、帮助命令

docker version				#显示docker的版本信息
docker info						#显示docker的系统信息,system级别的 包括容器和镜像的数量
docker --help  				#万能命令,能看到所有的命令

文档地址:https://docs.docker.com/reference/

二、镜像命令

2.2.1docker images 查看当前主机的所有镜像

# 1. 查询 images 的帮助命令
[root@iZhp3do4qhzu84445osa3sZ ~]# docker images --help

Usage:	docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print images using a Go template
      --help            Print usage
      --no-trunc        Don't truncate output
  -q, --quiet           Only show numeric IDs

# 2. docker images 查看所有本地主机上的镜像
[root@iZhp3do4qhzu84445osa3sZ ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
docker.io/rabbitmq          latest              7e50c60f7e3e        3 days ago          156 MB
docker.io/redis             latest              235592615444        10 days ago         104 MB
docker.io/nginx             latest              2622e6cca7eb        10 days ago         132 MB
docker.io/sonatype/nexus3   latest              57a6261043b9        2 months ago        644 MB
docker.io/hello-world       latest              bf756fb1ae65        5 months ago        13.3 kB
docker.io/mysql             5.7.25              984Z
REPOSITORY		当前镜像的仓库源
TAG						当前镜像的版本
IMAGE ID			当前镜像的ID
CREATED				当前创建时间
SIZE					当前镜像的文件大小
# asdzzzzzz z z z z
  -a, --all             # 列出所有的镜像
  -q, --quiet           # 只显示镜像的ID

2.2.2 docker search 搜索镜像

[root@iZhp3do4qhzu84445osa3sZ ~]# docker search mysql
INDEX       NAME                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mysql                             MySQL is a widely used, open-source relati...   9647      [OK]       
docker.io   docker.io/mariadb                           MariaDB is a community-developed fork of M...   3510      [OK]       
docker.io   docker.io/mysql/mysql-server                Optimized MySQL Server Docker images. Crea...   704                  [OK]

# 可选项
[root@iZhp3do4qhzu84445osa3sZ ~]# docker search --help
Usage:	docker search [OPTIONS] TERM
Search the Docker Hub for images
Options:
  -f, --filter filter   
      --help            Print usage
      --limit int       Max number of search results (default 25)
      --no-index        Don't truncate output
      --no-trunc        Don't truncate output
      
#  docker search mysql --filter=STARS=3000   通过filter来过滤名字为mysql 且stars大于3000的镜像  
[root@iZhp3do4qhzu84445osa3sZ ~]# docker search mysql --filter=STARS=3000
INDEX       NAME                DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mysql     MySQL is a widely used, open-source relati...   9647      [OK]       
docker.io   docker.io/mariadb   MariaDB is a community-developed fork of M...   3510      [OK]

2.2.3 docker pull 下载镜像

# docker pull 的帮助命令
[root@iZhp3do4qhzu84445osa3sZ ~]# docker pull --help
Usage:	docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Pull an image or a repository from a registry
Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --help                    Print usage

# docker pull mysql 
[root@iZhp3do4qhzu84445osa3sZ ~]# docker pull mysql
Using default tag: latest   #默认下载最新的版本
Trying to pull repository docker.io/library/mysql ... 

# 下载完成
[root@iZhp3do4qhzu84445osa3sZ ~]# docker pull mysql
Using default tag: latest
Trying to pull repository docker.io/library/mysql ... 
latest: Pulling from docker.io/library/mysql
8559a31e96f4: Already exists 
d51ce1c2e575: Pull complete # 分层下载  docker的核心 联合文件系统(后面讲)
c2344adc4858: Pull complete 
fcf3ceff18fc: Pull complete 
16da0c38dc5b: Pull complete 
b905d1797e97: Pull complete 
4b50d1c6b05c: Pull complete 
c75914a65ca2: Pull complete 
1ae8042bdd09: Pull complete 
453ac13c00a3: Pull complete 
9e680cd72f08: Pull complete 
a6b5dc864b6c: Pull complete 
Digest: sha256:8b7b328a7ff6de46ef96bcf83af048cb00a1c86282bfca0cb119c84568b4caf6 #签名
Status: Downloaded newer image for docker.io/mysql:latest  #真实的地址

# docker pull 等价于 docker pull docker.io/mysql:latest

# 下载指定的版本
[root@iZhp3do4qhzu84445osa3sZ ~]# docker pull mysql:5.7   #版本一定是官方仓库支持的版本
Trying to pull repository docker.io/library/mysql ... 
5.7: Pulling from docker.io/library/mysql
8559a31e96f4: Already exists #分层下载 很多镜像的内容是相同的就不会重复下载
d51ce1c2e575: Already exists #这样会极大地减少宿主机的内存损耗
c2344adc4858: Already exists 
fcf3ceff18fc: Already exists 
16da0c38dc5b: Already exists 
b905d1797e97: Already exists 
4b50d1c6b05c: Already exists 
d85174a87144: Pull complete 
a4ad33703fa8: Pull complete 
f7a5433ce20d: Pull complete 
3dcd2a278b4a: Pull complete 
Digest: sha256:32f9d9a069f7a735e28fd44ea944d53c61f990ba71460c5c183e610854ca4854
Status: Downloaded newer image for docker.io/mysql:5.7





2.2.4 docker rmi 删除镜像

# docker rmi --help 删除镜像的帮助手册
[root@iZhp3do4qhzu84445osa3sZ ~]# docker rimi --help
Usage:	docker COMMAND
A self-sufficient runtime for containers
Options:
      --config string      Location of client config files (default "/root/.docker")
  -D, --debug              Enable debug mode
      --help               Print usage
  -H, --host list          Daemon socket(s) to connect to (default [])
  -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 quit
  
# 根据image name 删除镜像   
[root@iZhp3do4qhzu84445osa3sZ ~]# docker rmi docker.io/mysql
Untagged: docker.io/mysql:latest
Untagged: docker.io/mysql@sha256:8b7b328a7ff6de46ef96bcf83af048cb00a1c86282bfca0cb119c84568b4caf6
Deleted: sha256:be0dbf01a0f3f46fc8c88b67696e74e7005c3e16d9071032fa0cd89773771576
Deleted: sha256:086d66e8d1cb0d52e9337eabb11fb9b95960e2e1628d90100c62ea5e8bf72306
Deleted: sha256:f37c61ee1973b18c285d0d5fcf02da4bcdb1f3920981499d2a20b2858500a110
Deleted: sha256:e40b8bca7dc63fc8d188a412328e56caf179022f5e5d5b323aae57d233fb1069
Deleted: sha256:339f6b96b27eb035cbedc510adad2560132925a835f0afddbcc1d311c961c14b
Deleted: sha256:d38b06cdb26a5c98857ddbc6ef531d3f57b00e325c0c314600b712efc7ff6ab0

# 根据 IMAGE ID 删除镜像
[root@iZhp3do4qhzu84445osa3sZ ~]# docker rmi 9cfcce23593a
Untagged: docker.io/mysql:5.7
Untagged: docker.io/mysql@sha256:32f9d9a069f7a735e28fd44ea944d53c61f990ba71460c5c183e610854ca4854
Deleted: sha256:9cfcce23593a93135ca6dbf3ed544d1db9324d4c40b5c0d56958165bfaa2d46a
Deleted: sha256:98de3e212919056def8c639045293658f6e6022794807d4b0126945ddc8324be
Deleted: sha256:17e8b88858e400f8c5e10e7cb3fbab9477f6d8aacba03b8167d34a91dbe4d8c1
Deleted: sha256:c04c087c2af9abd64ba32fe89d65e6d83da514758923de5da154541cc01a3a1e
Deleted: sha256:ab8bf065b402b99aec4f12c648535ef1b8dc954b4e1773bdffa10ae2027d3e00
Deleted: sha256:09687cd9cdf4c704fde969fdba370c2d848bc614689712bef1a31d0d581f2007
Deleted: sha256:b704a4a65bf536f82e5d8b86e633d19185e26313de8380162e778feb2852011a
Deleted: sha256:c37206160543786228aa0cce738e85343173851faa44bb4dc07dc9b7dc4ff1c1
Deleted: sha256:12912c9ec523f648130e663d9d4f0a47c1841a0064d4152bcf7b2a97f96326eb
Deleted: sha256:57d29ad88aa49f0f439592755722e70710501b366e2be6125c95accc43464844
Deleted: sha256:b17c024283d0302615c6f0c825137da9db607d49a83d2215a79733afbbaeb7c3

# docker rmi -f IMAGE ID IMAGE ID IMAGE ID IMAGE ID  #空格分割删除多个镜像
# docker rmi -f $(docker images -aq) #递归删除所有镜像
# 这里有比较重要的镜像 就不演示了

三、容器命令

说明:我们有了镜像才能创建容器,在docker中在装一个centos镜像来测试学习

2.3.1 docker run 启动容器

# 1. 下载一个最新版本的centos镜像
docker pull contos
# 2. 启动contos镜像
docker run [可选参数] image
#	2.1 介绍可选参数
--name="name"		#容器的别称  例如启动多个tomcat时   tomcat01 tomcat02 来区分容器
-d 						 	#后台方式运行
-it							#使用交互方式运行,进入容器查看内容
-p(小写)				#指定容器的端口  -p 8080:8080 
		-p 172.0.0.1:8080:8080  #ip:主机端口:容器端口
		-p  8080:8080           #主机端口:容器端口(常用)
		-p  8080                #容器端口
-P(大写)				#随机指定端口

# 3. 启动centos镜像 
[root@iZhp3do4qhzu84445osa3sZ ~]# docker run -it docker.io/centos /bin/bash    #启动并进入容器 ,以交互的方式,不然进不去
[root@9612d2aecd2f /]#     # 已经进入centos镜像的操作界面
# 4. 清楚的发现root@主机名称发生了改变
# 5. 查看centos镜像内部文件-本质上就是一个centos系统,只不过是基础版本,很多的命令不完善
[root@9612d2aecd2f /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var    #内部的centos和外部centos没有一点关系 
# 6. 退出当前centos镜像
[root@9612d2aecd2f /]# exit
exit
[root@iZhp3do4qhzu84445osa3sZ ~]#  # 清楚的发现root@主机名又一次发生了改变
# 7. 判断当前环境是centos镜像还是我们的宿主机centos系统
[root@iZhp3do4qhzu84445osa3sZ /]# ls
bin   dev  home        lib    lost+found  mnt         opt    proc  run   srv  temp  Users  var
boot  etc  install.sh  lib64  media       nexus-data  patch  root  sbin  sys  tmp   usr    www
[root@iZhp3do4qhzu84445osa3sZ /]#  # 可以发现现在的fileTree比上次查看的多很多,可以确定当前的环境为我们宿主机的centos系统

2.3.2 docker ps 查看运行的容器

# 1. docker ps --help  帮助手册
[root@iZhp3do4qhzu84445osa3sZ /]# docker ps --help
Usage:	docker ps [OPTIONS]
List containers
Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
      --help            Print usage
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes
  
# 2. docker ps  查看当前正在运行的镜像
[root@iZhp3do4qhzu84445osa3sZ /]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
3466fcdf89fb        sonatype/nexus3     "sh -c ${SONATYPE_..."   7 weeks ago         Up About an hour    0.0.0.0:8081->8081/tcp   nexus

# 3. docker ps -a 查看历史运行的镜像
[root@iZhp3do4qhzu84445osa3sZ /]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                               NAMES
9612d2aecd2f        docker.io/centos    "/bin/bash"              11 minutes ago      Exited (0) 6 minutes ago                                        friendly_jones
f8728bfa5820        docker.io/centos    "/bin/bash"              12 minutes ago      Exited (0) 12 minutes ago                                       objective_ardinghelli
223c74a730f5        docker.io/centos    "/bin/bash"              12 minutes ago      Exited (0) 12 minutes ago                                       amazing_keller
60c8aa9d8801        hello-world         "/hello"                 2 hours ago         Exited (0) 2 hours ago                                          goofy_meninsky
269c071b447b        mysql:5.7.25        "docker-entrypoint..."   3 weeks ago         Created                     33060/tcp, 0.0.0.0:3308->3306/tcp   mysql
3466fcdf89fb        sonatype/nexus3     "sh -c ${SONATYPE_..."   7 weeks ago         Up About an hour            0.0.0.0:8081->8081/tcp              nexus

# 4. docker ps -a -n=1  查看历史运行的镜像并且只显示一个  默认显示的是最近运行过的镜像
[root@iZhp3do4qhzu84445osa3sZ /]# docker ps -a -n=1
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
9612d2aecd2f        docker.io/centos    "/bin/bash"         13 minutes ago      Exited (0) 8 minutes ago                       friendly_jones

# 4. docker ps -aq   查看历史运行的镜像 并且只显示编号
[root@iZhp3do4qhzu84445osa3sZ /]# docker ps -aq
9612d2aecd2f
f8728bfa5820
223c74a730f5
60c8aa9d8801
269c071b447b
3466fcdf89fb

2.3.3 退出容器

exit 						# 直接容器停止并退出
Ctrl + P + Q 		# 容器不停止并且退出

2.3.4 docker rm 删除容器

docker rm 容器ID								#根据容器的id进行删除 不能删除正在运行的容器,如果想强制删除 -f
docker rm -f $(docker ps -aq)		#递归删除所有容器

2.3.5 启动和停止容器

docker start [容器ID]  		# 根据容器ID 启动容器
docker restart [容器ID] 	# 根据容器ID 重启容器
docker stop [容器ID] 			# 根据容器ID 停止当前运行的容器
docker kill[容器ID]				# 根据容器ID 强制停止当前运行的容器进程

四、常用的其他命令

2.4.1 后台启动容器

# 命令 docker run -d [镜像名称]
# 问题:docker ps 发现centos 停止了
# 常见的坑: docker 容器使用后台运行,就必须要有一个前台进程,docker 发现没有应用,就会停止
# nginx:容器启动后,发现自己没有提供服务,就会自动停止,就是没有程序了

2.4.2 查看日志

docker logs -tf --tail [容器ID]   # 如果没有日志

# 自己编写一段shell脚本
docker run -d centos /bin/sh -c "while true;do echo hzbs;slepp 1;done"
# 显示日志
-tf
--tail [NUMBER] #要显示的日志的行数

2.4.3 docker top [容器ID]查看容器中的进程信息

[root@iZhp3do4qhzu84445osa3sZ ~]# docker top 3466fcdf89fb
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
200                 6293                6275                0                   Jun20               ?                   00:01:51            /usr/lib/jvm/java-1.8.0/bin/java -server -Dinstall4j.jvmDir=/usr/lib/jvm/java-1.8.0 -Dexe4j.moduleName=/opt/sonatype/nexus/bin/nexus -XX:+UnlockDiagnosticVMOptions -Dinstall4j.launcherId=245 -Dinstall4j.swt=false -Di4jv=0 -Di4jv=0 -Di4jv=0 -Di4jv=0 -Di4jv=0 -Xms1200m -Xmx1200m -XX:MaxDirectMemorySize=2g -Djava.util.prefs.userRoot=/nexus-data/javaprefs -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=../sonatype-work/nexus3/log/jvm.log -XX:-OmitStackTraceInFastThrow -Djava.net.preferIPv4Stack=true -Dkaraf.home=. -Dkaraf.base=. -Dkaraf.etc=etc/karaf -Djava.util.logging.config.file=etc/karaf/java.util.logging.properties -Dkaraf.data=../sonatype-work/nexus3 -Dkaraf.log=../sonatype-work/nexus3/log -Djava.io.tmpdir=../sonatype-work/nexus3/tmp -Dkaraf.startLocalConsole=false -Djava.endorsed.dirs=lib/endorsed -Di4j.vpt=true -classpath /opt/sonatype/nexus/.install4j/i4jruntime.jar:/opt/sonatype/nexus/lib/boot/nexus-main.jar:/opt/sonatype/nexus/lib/boot/activation-1.1.1.jar:/opt/sonatype/nexus/lib/boot/jaxb-api-2.2.7.jar:/opt/sonatype/nexus/lib/boot/jaxb-core-2.2.7.jar:/opt/sonatype/nexus/lib/boot/jaxb-impl-2.2.7.jar:/opt/sonatype/nexus/lib/boot/org.apache.karaf.main-4.2.6.jar:/opt/sonatype/nexus/lib/boot/org.osgi.core-6.0.0.jar:/opt/sonatype/nexus/lib/boot/org.apache.karaf.specs.activator-4.2.6.jar:/opt/sonatype/nexus/lib/boot/org.apache.karaf.diagnostic.boot-4.2.6.jar:/opt/sonatype/nexus/lib/boot/org.apache.karaf.jaas.boot-4.2.6.jar com.install4j.runtime.launcher.UnixLauncher run 9d17dc87 0 0 org.sonatype.nexus.karaf.NexusMain


2.4.4 docker inspect [容器的ID]查看容器内部的源数据

[root@iZhp3do4qhzu84445osa3sZ ~]# docker inspect 3466fcdf89fb   #这里查看的是nexus3的源数据
[
    {
    
    
        "Id": "3466fcdf89fb1c6b81ded2ec0798775726073e631ae9620126f314b43c0f930d", #镜像的ID 我们发现镜像的ID 只是这个源数据ID 的缩写
        "Created": "2020-04-28T09:52:14.822841264Z", #镜像的创建时间
        "Path": "sh", # 镜像默认的控制台
        "Args": [
            "-c",
            "${SONATYPE_DIR}/start-nexus-repository-manager.sh" # 这是传递的一些参数
        ],
        "State": {
    
      #当前容器的一些状态
            "Status": "running", #现在的状态是正在运行的状态
            "Running": true, # 是否是在运行中 true
            "Paused": false, 
            "Restarting": false,  # 是否重启
            "OOMKilled": false,
            "Dead": false,
            "Pid": 6293, # PID
            "ExitCode": 0, 
            "Error": "", #错误信息
            "StartedAt": "2020-06-20T12:36:09.758584728Z", #容器的启动时间
            "FinishedAt": "2020-06-20T12:36:06.899669804Z" # 获取容器的时间
        },
        "Image": "sha256:57a6261043b9a2809b52053fb01733610366f9f80af18501d48e85cb0d2148f2",  #镜像的ID
        "ResolvConfPath": "/var/lib/docker/containers/3466fcdf89fb1c6b81ded2ec0798775726073e631ae9620126f314b43c0f930d/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/3466fcdf89fb1c6b81ded2ec0798775726073e631ae9620126f314b43c0f930d/hostname",
        "HostsPath": "/var/lib/docker/containers/3466fcdf89fb1c6b81ded2ec0798775726073e631ae9620126f314b43c0f930d/hosts",
        "LogPath": "",
        "Name": "/nexus",
        "RestartCount": 0,
        "Driver": "overlay2",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
    
    
            "Binds": [
                "/nexus-data:/var/nexus-data"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
    
    
                "Type": "journald",
                "Config": {
    
    }
            },
            "NetworkMode": "default",
            "PortBindings": {
    
    
                "8081/tcp": [
                    {
    
    
                        "HostIp": "",
                        "HostPort": "8081"
                    }
                ]
            },
            "RestartPolicy": {
    
    
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "docker-runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
    
    
            "Name": "overlay2",
            "Data": {
    
    
                "LowerDir": "/var/lib/docker/overlay2/122fa03557b6065b4e14884bf37b223ce0835355c980fdf5ce65614977a111b5-init/diff:/var/lib/docker/overlay2/062887da31267e8551df829263419b33df22e6d0d274f5dc2cd108ae69b28f39/diff:/var/lib/docker/overlay2/0e217b61c602950ac6d3aad10b39e89c1465da8d5d4ea4e6e218608498d13920/diff:/var/lib/docker/overlay2/3769ecec094b62895507ce4e32371523ffc955d9fc12ca003e3eaa63fbef1f81/diff:/var/lib/docker/overlay2/17c05ff7dece3f81685699b6390c26d310a49634ab6472d7580678c36dd11bb3/diff",
                "MergedDir": "/var/lib/docker/overlay2/122fa03557b6065b4e14884bf37b223ce0835355c980fdf5ce65614977a111b5/merged",
                "UpperDir": "/var/lib/docker/overlay2/122fa03557b6065b4e14884bf37b223ce0835355c980fdf5ce65614977a111b5/diff",
                "WorkDir": "/var/lib/docker/overlay2/122fa03557b6065b4e14884bf37b223ce0835355c980fdf5ce65614977a111b5/work"
            }
        },
        "Mounts": [
            {
    
    
                "Type": "volume",
                "Name": "0550769d1bc43d2f378736f1e6365b25c0fd4234a9438165fa67107fdc33e04f",
                "Source": "/var/lib/docker/volumes/0550769d1bc43d2f378736f1e6365b25c0fd4234a9438165fa67107fdc33e04f/_data",
                "Destination": "/nexus-data",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
    
    
                "Type": "bind",
                "Source": "/nexus-data",
                "Destination": "/var/nexus-data",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
    
    
            "Hostname": "3466fcdf89fb",
            "Domainname": "",
            "User": "nexus",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
    
    
                "8081/tcp": {
    
    }
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "container=oci",
                "SONATYPE_DIR=/opt/sonatype",
                "NEXUS_HOME=/opt/sonatype/nexus",
                "NEXUS_DATA=/nexus-data",
                "NEXUS_CONTEXT=",
                "SONATYPE_WORK=/opt/sonatype/sonatype-work",
                "DOCKER_TYPE=rh-docker",
                "INSTALL4J_ADD_VM_PARAMS=-Xms1200m -Xmx1200m -XX:MaxDirectMemorySize=2g -Djava.util.prefs.userRoot=/nexus-data/javaprefs"
            ],
            "Cmd": [
                "sh",
                "-c",
                "${SONATYPE_DIR}/start-nexus-repository-manager.sh"
            ],
            "ArgsEscaped": true,
            "Image": "sonatype/nexus3",
            "Volumes": {
    
    
                "/nexus-data": {
    
    }
            },
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
    
    
                "architecture": "x86_64",
                "authoritative-source-url": "registry.access.redhat.com",
                "build-date": "2020-03-31T14:54:13.907559",
                "com.redhat.build-host": "cpt-1007.osbs.prod.upshift.rdu2.redhat.com",
                "com.redhat.component": "ubi8-container",
                "com.redhat.license_terms": "https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI",
                "com.sonatype.license": "Apache License, Version 2.0",
                "com.sonatype.name": "Nexus Repository Manager base image",
                "description": "The Nexus Repository Manager server           with universal support for popular component formats.",
                "distribution-scope": "public",
                "io.k8s.description": "The Nexus Repository Manager server           with universal support for popular component formats.",
                "io.k8s.display-name": "Nexus Repository Manager",
                "io.openshift.expose-services": "8081:8081",
                "io.openshift.tags": "Sonatype,Nexus,Repository Manager",
                "maintainer": "Sonatype <[email protected]>",
                "name": "Nexus Repository Manager",
                "release": "3.22.1",
                "run": "docker run -d --name NAME           -p 8081:8081           IMAGE",
                "stop": "docker stop NAME",
                "summary": "The Nexus Repository Manager server           with universal support for popular component formats.",
                "url": "https://sonatype.com",
                "vcs-ref": "26f36bfa3e3a04c8c866b250924c1aefc34f01c9",
                "vcs-type": "git",
                "vendor": "Sonatype",
                "version": "3.22.1-02"
            }
        },
        "NetworkSettings": {
    
    
            "Bridge": "",
            "SandboxID": "8b429d91787273732c6fd3e5f9d8c29d9d14ee947be3844e3943c10a6c437e37",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
    
    
                "8081/tcp": [
                    {
    
    
                        "HostIp": "0.0.0.0",
                        "HostPort": "8081"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/8b429d917872",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "54b20e2bc6a9beb2f7bd46486786d7adce02e87b9b874a847361e7a08a07357a",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
    
     													#Docker 的网络  现在是一个桥接的模式
                "bridge": {
    
    
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "dc54f1fd667b171fe51b564ad169e04c087d655b8f70fc08bc651de1c2fd5f7e",
                    "EndpointID": "54b20e2bc6a9beb2f7bd46486786d7adce02e87b9b874a847361e7a08a07357a",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02"
                }
            }
        }
    }
]

2.4.5 docker exec -it [容器ID] /bashShell进入当前运行的容器

# 通常我们容器都是使用后台的方式运行的,需要进入容器修改一些配置的时候
# 方式一 docker exec -it [容器ID] bashShell  # 进入容器后开启一个新的终端,可以在里面进行操作
# 方式二 docker attach   										# 进入的是容器正在执行的终端
[root@iZhp3do4qhzu84445osa3sZ ~]# docker attach --help
Usage:	docker attach [OPTIONS] CONTAINER
Attach to a running container
Options:
      --detach-keys string   Override the key sequence for detaching a container
      --help                 Print usage
      --no-stdin             Do not attach STDIN
      --sig-proxy            Proxy all received signals to the process (default true)
      

2.4.6 从容器中把文件拷贝到宿主机上

# docker cp [容器ID] #从容器的内部拷贝文件到宿主机上

[root@iZhp3do4qhzu84445osa3sZ home]# docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
5b0be096576e        docker.io/sonatype/nexus3   "sh -c ${SONATYPE_..."   18 minutes ago      Up 18 minutes       0.0.0.0:8081->8081/tcp   nexus3
[root@iZhp3do4qhzu84445osa3sZ home]# docker cp 5b0be096576e:/nexus-data/admin.password /home
[root@iZhp3do4qhzu84445osa3sZ home]# cd /home/
[root@iZhp3do4qhzu84445osa3sZ home]# ls
admin.password  nexus  nexus-data  www
[root@iZhp3do4qhzu84445osa3sZ home]# 

# 现在的拷贝是一个手动的过程  未来我们会使用 -v 卷的技术, 可以实现容器内文件和宿主机文件互通

2.4.7 小结

在这里插入图片描述

五、安装常用组件

2.5.1 安装Nginx

安装nginx

# 1. docker search nginx  #搜索镜像
[root@iZhp3do4qhzu84445osa3sZ /]# docker search nginx
INDEX       NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/nginx                              Official build of Nginx.                        13358     [OK]       
docker.io   docker.io/jwilder/nginx-proxy                Automated Nginx reverse proxy for docker c...   1824                 [OK]
docker.io   docker.io/richarvey/nginx-php-fpm            Container running Nginx + PHP-FPM capable ...   778                  [OK]
docker.io   docker.io/linuxserver/nginx                  An Nginx container, brought to you by Linu...   115                  
docker.io   docker.io/bitnami/nginx                      Bitnami nginx Docker Image                      85                   [OK]
docker.io   docker.io/tiangolo/nginx-rtmp                Docker image with Nginx using the nginx-rt...   76                   [OK]
docker.io   docker.io/alfg/nginx-rtmp                    NGINX, nginx-rtmp-module and FFmpeg from s...   69                   [OK]
docker.io   docker.io/jc21/nginx-proxy-manager           Docker container for managing Nginx proxy ...   65                   
docker.io   docker.io/nginxdemos/hello                   NGINX webserver that serves a simple page ...   53                   [OK]
docker.io   docker.io/jlesage/nginx-proxy-manager        Docker container for Nginx Proxy Manager        47                   [OK]
docker.io   docker.io/nginx/nginx-ingress                NGINX Ingress Controller for Kubernetes         33                   
docker.io   docker.io/privatebin/nginx-fpm-alpine        PrivateBin running on an Nginx, php-fpm & ...   27                   [OK]
docker.io   docker.io/schmunk42/nginx-redirect           A very simple container to redirect HTTP t...   18                   [OK]
docker.io   docker.io/nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                  16                   
docker.io   docker.io/blacklabelops/nginx                Dockerized Nginx Reverse Proxy Server.          13                   [OK]
docker.io   docker.io/centos/nginx-112-centos7           Platform for running nginx 1.12 or buildin...   13                   
docker.io   docker.io/centos/nginx-18-centos7            Platform for running nginx 1.8 or building...   13                   
docker.io   docker.io/raulr/nginx-wordpress              Nginx front-end for the official wordpress...   13                   [OK]
docker.io   docker.io/nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter                       12                   
docker.io   docker.io/mailu/nginx                        Mailu nginx frontend                            7                    [OK]
docker.io   docker.io/sophos/nginx-vts-exporter          Simple server that scrapes Nginx vts stats...   7                    [OK]
docker.io   docker.io/bitnami/nginx-ingress-controller   Bitnami Docker Image for NGINX Ingress Con...   5                    [OK]
docker.io   docker.io/bitwarden/nginx                    The Bitwarden nginx web server acting as a...   5                    
docker.io   docker.io/ansibleplaybookbundle/nginx-apb    An APB to deploy NGINX                          1                    [OK]
docker.io   docker.io/wodby/nginx                        Generic nginx 

# 2. docker pull docker.io/nginx  #下载镜像
[root@iZhp3do4qhzu84445osa3sZ /]# docker pull docker.io/nginx
Using default tag: latest
Trying to pull repository docker.io/library/nginx ... 
latest: Pulling from docker.io/library/nginx
8559a31e96f4: Already exists 
8d69e59170f7: Pull complete 
3f9f1ec1d262: Pull complete 
d1f5ff4f210d: Pull complete 
1e22bfa8652e: Pull complete 
Digest: sha256:21f32f6c08406306d822a0e6e8b7dc81f53f336570e852e25fbe1e3e3d0d0133
Status: Downloaded newer image for docker.io/nginx:latest
[root@iZhp3do4qhzu84445osa3sZ /]# docker images   #查看nginx镜像
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
docker.io/rabbitmq          latest              7e50c60f7e3e        3 days ago          156 MB
docker.io/centos            latest              831691599b88        3 days ago          215 MB
docker.io/redis             latest              235592615444        10 days ago         104 MB
docker.io/nginx             latest              2622e6cca7eb        11 days ago         132 MB
docker.io/sonatype/nexus3   latest              e56a3b1f769b        12 days ago         630 MB
docker.io/mysql             5.7.25              98455b9624a9        15 months ago       372 MB

# 3. docker run -d --name nginx01 -p 17200:80 docker.io/nginx  启动nginx
# 参数:
		# -d 							后台运行
		# --name nginx01  重命名为nginx01
		# -p 17200:80  		将镜像内的80端口映射到宿主机的17200端口
[root@iZhp3do4qhzu84445osa3sZ /]# docker run -d --name nginx01 -p 17200:80 docker.io/nginx
48abd2f7180a03684a24f13f9c063a395c438abe85f2633e4d286a786ee22e13
[root@iZhp3do4qhzu84445osa3sZ /]# docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
48abd2f7180a        docker.io/nginx             "/docker-entrypoin..."   11 seconds ago      Up 11 seconds       0.0.0.0:17200->80/tcp    nginx01
5b0be096576e        docker.io/sonatype/nexus3   "sh -c ${SONATYPE_..."   57 minutes ago      Up 57 minutes       0.0.0.0:8081->8081/tcp   nexus3
# 测试nginx是否启动
[root@iZhp3do4qhzu84445osa3sZ /]# curl localhost:17200
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
    
    
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html> 

遇到的问题: 我们每次改动nginx的配置文件都要进入容器的内部?非常的麻烦,我要是可以再容器外部提供一个映射路径,映射到nginx的配置文件,以后在宿主机上修改文件,容器内部的文件也可以自动修改? -v 数据卷 后面讲

2.5.2 安装tomcat

安装tomcat

# 官方的使用
docker run -it --rm tomcat:9.0  # 一般用来测试  阅后即焚
# 我们之前的启动  都是后台停止了容器之后,容器还是可以查到,所以还是按照我们之前的方式
# 1. docker pull tomcat
# 2. docker run -d --name tomcat01 -p 17500:8080 docker.io/tomcat
# 3. 测试tomcat01  curl localhost:17500
[root@iZhp3do4qhzu84445osa3sZ /]# curl localhost:17500
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {
    
    font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {
    
    color:white;background-color:#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/9.0.36</h3></body></html>

# 发现是404页面 这是为什么呢?我们进入容器内部看一下

[root@iZhp3do4qhzu84445osa3sZ /]# docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                     NAMES
afbd9cc1bd41        docker.io/tomcat            "catalina.sh run"        4 minutes ago       Up 4 minutes        0.0.0.0:17500->8080/tcp   tomcat01
48abd2f7180a        docker.io/nginx             "/docker-entrypoin..."   34 minutes ago      Up 23 minutes       0.0.0.0:17200->80/tcp     nginx01
5b0be096576e        docker.io/sonatype/nexus3   "sh -c ${SONATYPE_..."   About an hour ago   Up About an hour    0.0.0.0:8081->8081/tcp    nexus3
[root@iZhp3do4qhzu84445osa3sZ /]# docker exec -it afbd9cc1bd41 /bin/bash
root@afbd9cc1bd41:/usr/local/tomcat# ls
BUILDING.txt	 LICENSE  README.md	 RUNNING.txt  conf  logs	    temp     webapps.dist
CONTRIBUTING.md  NOTICE   RELEASE-NOTES  bin	      lib   native-jni-lib  webapps  work

# 进入webapps
root@afbd9cc1bd41:/usr/local/tomcat# cd webapps
root@afbd9cc1bd41:/usr/local/tomcat/webapps# ls
root@afbd9cc1bd41:/usr/local/tomcat/webapps# 

# 发现webapps下面是空的   说明官方的tomcat是阉割版本,但是我们发现多了一个webapps.dist文件我们打开这个文件
root@afbd9cc1bd41:/usr/local/tomcat# cd webapps.dist/
root@afbd9cc1bd41:/usr/local/tomcat/webapps.dist# ls
ROOT  docs  examples  host-manager  manager

# 发现这里面有我们需要的文件,所以我们将webapps.dist 下的文件拷贝到webapps文件中
cp -r ../webapps.dist/* webapps

# 再次测试
exit
curl localhost:17500

[root@iZhp3do4qhzu84445osa3sZ /]# curl localhost:17500



<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Apache Tomcat/9.0.36</title>
        <link href="favicon.ico" rel="icon" type="image/x-icon" />
        <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <link href="tomcat.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
        <div id="wrapper">
            <div id="navigation" class="curved container">
                <span id="nav-home"><a href="https://tomcat.apache.org/">Home</a></span>
                <span id="nav-hosts"><a href="/docs/">Documentation</a></span>
                <span id="nav-config"><a href="/docs/config/">Configuration</a></span>
                <span id="nav-examples"><a href="/examples/">Examples</a></span>
                <span id="nav-wiki"><a href="https://wiki.apache.org/tomcat/FrontPage">Wiki</a></span>
                <span id="nav-lists"><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></span>
                <span id="nav-help"><a href="https://tomcat.apache.org/findhelp.html">Find Help</a></span>
                <br class="separator" />
            </div>
            <div id="asf-box">
                <h1>Apache Tomcat/9.0.36</h1>
            </div>
            <div id="upper" class="curved container">
                <div id="congrats" class="curved container">
                    <h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
                </div>
                <div id="notice">
                    <img src="tomcat.png" alt="[tomcat logo]" />
                    <div id="tasks">
                        <h3>Recommended Reading:</h3>
                        <h4><a href="/docs/security-howto.html">Security Considerations How-To</a></h4>
                        <h4><a href="/docs/manager-howto.html">Manager Application How-To</a></h4>
                        <h4><a href="/docs/cluster-howto.html">Clustering/Session Replication How-To</a></h4>
                    </div>
                </div>
                <div id="actions">
                    <div class="button">
                        <a class="container shadow" href="/manager/status"><span>Server Status</span></a>
                    </div>
                    <div class="button">
                        <a class="container shadow" href="/manager/html"><span>Manager App</span></a>
                    </div>
                    <div class="button">
                        <a class="container shadow" href="/host-manager/html"><span>Host Manager</span></a>
                    </div>
                </div>
                <br class="separator" />
            </div>
            <div id="middle" class="curved container">
                <h3>Developer Quick Start</h3>
                <div class="col25">
                    <div class="container">
                        <p><a href="/docs/setup.html">Tomcat Setup</a></p>
                        <p><a href="/docs/appdev/">First Web Application</a></p>
                    </div>
                </div>
                <div class="col25">
                    <div class="container">
                        <p><a href="/docs/realm-howto.html">Realms &amp; AAA</a></p>
                        <p><a href="/docs/jndi-datasource-examples-howto.html">JDBC DataSources</a></p>
                    </div>
                </div>
                <div class="col25">
                    <div class="container">
                        <p><a href="/examples/">Examples</a></p>
                    </div>
                </div>
                <div class="col25">
                    <div class="container">
                        <p><a href="https://wiki.apache.org/tomcat/Specifications">Servlet Specifications</a></p>
                        <p><a href="https://wiki.apache.org/tomcat/TomcatVersions">Tomcat Versions</a></p>
                    </div>
                </div>
                <br class="separator" />
            </div>
            <div id="lower">
                <div id="low-manage" class="">
                    <div class="curved container">
                        <h3>Managing Tomcat</h3>
                        <p>For security, access to the <a href="/manager/html">manager webapp</a> is restricted.
                        Users are defined in:</p>
                        <pre>$CATALINA_HOME/conf/tomcat-users.xml</pre>
                        <p>In Tomcat 9.0 access to the manager application is split between
                           different users. &nbsp; <a href="/docs/manager-howto.html">Read more...</a></p>
                        <br />
                        <h4><a href="/docs/RELEASE-NOTES.txt">Release Notes</a></h4>
                        <h4><a href="/docs/changelog.html">Changelog</a></h4>
                        <h4><a href="https://tomcat.apache.org/migration.html">Migration Guide</a></h4>
                        <h4><a href="https://tomcat.apache.org/security.html">Security Notices</a></h4>
                    </div>
                </div>
                <div id="low-docs" class="">
                    <div class="curved container">
                        <h3>Documentation</h3>
                        <h4><a href="/docs/">Tomcat 9.0 Documentation</a></h4>
                        <h4><a href="/docs/config/">Tomcat 9.0 Configuration</a></h4>
                        <h4><a href="https://wiki.apache.org/tomcat/FrontPage">Tomcat Wiki</a></h4>
                        <p>Find additional important configuration information in:</p>
                        <pre>$CATALINA_HOME/RUNNING.txt</pre>
                        <p>Developers may be interested in:</p>
                        <ul>
                            <li><a href="https://tomcat.apache.org/bugreport.html">Tomcat 9.0 Bug Database</a></li>
                            <li><a href="/docs/api/index.html">Tomcat 9.0 JavaDocs</a></li>
                            <li><a href="https://github.com/apache/tomcat/tree/master">Tomcat 9.0 Git Repository at GitHub</a></li>
                        </ul>
                    </div>
                </div>
                <div id="low-help" class="">
                    <div class="curved container">
                        <h3>Getting Help</h3>
                        <h4><a href="https://tomcat.apache.org/faq/">FAQ</a> and <a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></h4>
                        <p>The following mailing lists are available:</p>
                        <ul>
                            <li id="list-announce"><strong><a href="https://tomcat.apache.org/lists.html#tomcat-announce">tomcat-announce</a><br />
                                Important announcements, releases, security vulnerability notifications. (Low volume).</strong>
                            </li>
                            <li><a href="https://tomcat.apache.org/lists.html#tomcat-users">tomcat-users</a><br />
                                User support and discussion
                            </li>
                            <li><a href="https://tomcat.apache.org/lists.html#taglibs-user">taglibs-user</a><br />
                                User support and discussion for <a href="https://tomcat.apache.org/taglibs/">Apache Taglibs</a>
                            </li>
                            <li><a href="https://tomcat.apache.org/lists.html#tomcat-dev">tomcat-dev</a><br />
                                Development mailing list, including commit messages
                            </li>
                        </ul>
                    </div>
                </div>
                <br class="separator" />
            </div>
            <div id="footer" class="curved container">
                <div class="col20">
                    <div class="container">
                        <h4>Other Downloads</h4>
                        <ul>
                            <li><a href="https://tomcat.apache.org/download-connectors.cgi">Tomcat Connectors</a></li>
                            <li><a href="https://tomcat.apache.org/download-native.cgi">Tomcat Native</a></li>
                            <li><a href="https://tomcat.apache.org/taglibs/">Taglibs</a></li>
                            <li><a href="/docs/deployer-howto.html">Deployer</a></li>
                        </ul>
                    </div>
                </div>
                <div class="col20">
                    <div class="container">
                        <h4>Other Documentation</h4>
                        <ul>
                            <li><a href="https://tomcat.apache.org/connectors-doc/">Tomcat Connectors</a></li>
                            <li><a href="https://tomcat.apache.org/connectors-doc/">mod_jk Documentation</a></li>
                            <li><a href="https://tomcat.apache.org/native-doc/">Tomcat Native</a></li>
                            <li><a href="/docs/deployer-howto.html">Deployer</a></li>
                        </ul>
                    </div>
                </div>
                <div class="col20">
                    <div class="container">
                        <h4>Get Involved</h4>
                        <ul>
                            <li><a href="https://tomcat.apache.org/getinvolved.html">Overview</a></li>
                            <li><a href="https://tomcat.apache.org/source.html">Source Repositories</a></li>
                            <li><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></li>
                            <li><a href="https://wiki.apache.org/tomcat/FrontPage">Wiki</a></li>
                        </ul>
                    </div>
                </div>
                <div class="col20">
                    <div class="container">
                        <h4>Miscellaneous</h4>
                        <ul>
                            <li><a href="https://tomcat.apache.org/contact.html">Contact</a></li>
                            <li><a href="https://tomcat.apache.org/legal.html">Legal</a></li>
                            <li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
                            <li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
                        </ul>
                    </div>
                </div>
                <div class="col20">
                    <div class="container">
                        <h4>Apache Software Foundation</h4>
                        <ul>
                            <li><a href="https://tomcat.apache.org/whoweare.html">Who We Are</a></li>
                            <li><a href="https://tomcat.apache.org/heritage.html">Heritage</a></li>
                            <li><a href="https://www.apache.org">Apache Home</a></li>
                            <li><a href="https://tomcat.apache.org/resources.html">Resources</a></li>
                        </ul>
                    </div>
                </div>
                <br class="separator" />
            </div>
            <p class="copyright">Copyright &copy;1999-2020 Apache Software Foundation.  All Rights Reserved</p>
        </div>
    </body>

</html>
# 这时我们发现我们熟悉的tomcat的index页面回来了,就说明我们的tomcat容器启动成功了


思考问题: 我们以后每次部署项目的时候,每次都要进入容器内部非常的麻烦,如果我们在容器的外部也就是我们的宿主机上提供一个映射的路径的话,webapps, 我们在外部放置项目,就自动同步到容器内部就好了!

2.5.3 安装ES+kibana

安装ES +kibana

# es 暴露的端口很多
# es 是很消耗内存
# es 的数据一般需要放置到安全的目录!挂载

# 启动es -1核心2G的服务器请慎重,服务器会挂掉!!!!! 我这2核4G稍微不卡
docker run -d --name es01 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2

# 测试是否安装成功 
[root@iZhp3do4qhzu84445osa3sZ /]# curl localhost:9200
{
    
    
  "name" : "1bbbf8741afb",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "1260aKbCQWagUnNRyq-oMA",
  "version" : {
    
    
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

# 增加对ES的内存限制,之前的方式是修改配置文件   -e 修改配置
docker run -d --name es02 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms258m -Xms1024m" elasticsearch:7.6.2

# docker stats # 查看cpu占用率
CONTAINER           CPU %               MEM USAGE / LIMIT       MEM %               NET I/O             BLOCK I/O           PIDS
272b65fe3867        0.48%               1.222 GiB / 3.518 GiB   34.75%              0 B / 656 B         154 MB / 729 kB     42
afbd9cc1bd41        0.06%               138.6 MiB / 3.518 GiB   3.85%               12.5 kB / 78.9 kB   34.3 MB / 0 B       36
48abd2f7180a        0.00%               1.41 MiB / 3.518 GiB    0.04%               2.72 kB / 1.48 kB   0 B / 0 B           2
5b0be096576e        0.29%               1.522 GiB / 3.518 GiB   43.26%              2.02 MB / 10.8 MB   57.2 MB / 138 MB    84


安装 Kibana

通过Kibana去控制ES需要连接ES,Docker中容器和容器是相互独立的 所以不能直接连接
在这里插入图片描述

六、可视化

  • portainer(暂时先用这个)
  • Rancher(CI/CD)(持续集成/持续部署)时在用

2.6.1 什么是portainer?

Docker图形化界面管理工具! 提供一个后台面板提供我们操作

docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer

第一次进入Portainer的后台管理界面需要设置一个密码

在这里插入图片描述
设置完密码之后选择local

在这里插入图片描述
不推荐使用,平时测试的时候玩一下就好了! 敲命令行的时候才是最帅的!

猜你喜欢

转载自blog.csdn.net/qq_39381775/article/details/106929240