Docker的基本命令、小练习、docker可视化、commit镜像
镜像命令
[root@VM-8-14-centos docker]# docker images
# 解释
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 5 months ago 13.3kB
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE ID 镜像的id
CREATED 镜像的创建时间
SIZE 镜像的大小
# 可选项
-a, --all #列出所有的命令
-q,--quiet #只显示id
docker search 搜索镜像
[root@VM-8-14-centos docker]# docker search mysql
NAME DESCRIPTION STARS
mysql MySQL is a widely used, open-source relation… 11294
mariadb MariaDB Server is a high performing open sou… 4289
mysql/mysql-server Optimized MySQL Server Docker images. Create… 837
#可选项 通过收藏来过滤
--filter=STARS=3000 搜索出来的镜像就是STARS数量大于3000的
docker pull 下载镜像
[root@VM-8-14-centos docker]# docker pull mysql
Using default tag: latest #没写tag的话,默认是使用最新版本latest
latest: Pulling from library/mysql
e1acddbe380c: Pulling fs layer #分层下载,docker的核心,联合文件系统
bed879327370: Pulling fs layer
03285f80bafd: Pulling fs layer
ccc17412a00a: Pull complete
1f556ecc09d1: Pull complete
adc5528e468d: Pull complete
1afc286d5d53: Pull complete
6c724a59adff: Pull complete
0f2345f8b0a3: Pull complete
c8461a25b23b: Pull complete
3adb49279bed: Pull complete
77f22cd6c363: Pull complete
Digest: sha256:d45561a65aba6edac77be36e0a53f0c1fba67b951cb728348522b671ad63f926 #签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest #真实地址
#docker pull mysql 等价于 docker pull docker.io/library/mysql:latest
#指定版本下载
[root@VM-8-14-centos docker]# docker pull mysql:5.7
5.7: Pulling from library/mysql
e1acddbe380c: Already exists #已经有了的就不会进行下载
bed879327370: Already exists #这样更节省内存
03285f80bafd: Already exists
ccc17412a00a: Already exists
1f556ecc09d1: Already exists
adc5528e468d: Already exists
1afc286d5d53: Already exists
4d2d9261e3ad: Pull complete #只下载了四个层级
ac609d7b31f8: Pull complete
53ee1339bc3a: Pull complete
b0c0a831a707: Pull complete
Digest: sha256:7cf2e7d7ff876f93c8601406a5aa17484e6623875e64e7acc71432ad8e0a3d7e
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
docker 删除镜像
#通过id删除一个镜像,也可以通过名字删除
[root@VM-8-14-centos docker]# docker rmi -f 6c20ffa54f86
Untagged: mysql:5.7
Untagged: mysql@sha256:7cf2e7d7ff876f93c8601406a5aa17484e6623875e64e7acc71432ad8e0a3d7e
Deleted: sha256:6c20ffa54f8674203e91e3225e489aa505fa04b8d482954a8b6d7414842c6de4
Deleted: sha256:7ecf077dd9d6725f0e594b9cd5eb214ad1b3764fa75bf5940ab08b05b8bae184
Deleted: sha256:c28edab85681de37f9d2a75dde941a20d2e1ac6e4efb7dee391913d3ec722fef
Deleted: sha256:6c11b187da1ecb65ce10b25f54354f3515ce9d26fabcd859cdb43dbd625df907
Deleted: sha256:d0dfc5be0883ed4af9f642a8e4f2312a93c4241ec8e89f22219b0f0a0d26c8d3
#删除所有的docker镜像
[root@VM-8-14-centos docker]# docker rmi -f $(docker images -aq)
Untagged: mysql:latest
Untagged: mysql@sha256:d45561a65aba6edac77be36e0a53f0c1fba67b951cb728348522b671ad63f926
Deleted: sha256:5a4e492065c722ec8cc7413552bafc6fd5434c5ad90797e898ccc4e347e21aa5
Deleted: sha256:816bf92c28337cd97393cb1fab7697398c9b657baa8e80ad394e1193bdd7c323
Deleted: sha256:4d9cad11f64589b397b1033d6f14cea1794efbee0a9923932fb3394a67cb9812
Deleted: sha256:d8cc28a31b469770ffe2239a29aaef8745fedc4df3c545b1615ba864796709a3
Deleted: sha256:c65a377e07f1205f3c28f7067d2ac4da3a65fbe7c1b4606b48028db3818d2f4c
Deleted: sha256:7dcd840f1d4be1a565f470453489932a17c62ed36b959d7839f004606ba22f0b
Deleted: sha256:1438a7497295aed687ea1875073a1f9faa6a308f787767b952da4a1a21e2c2c6
Deleted: sha256:c728863b4742db55b9630b0129abac718c8c9704e5ed86e8af93dfb47a0f6214
Deleted: sha256:0f12df3ff796b6fb619c63bf2f78f16d1033746e19f75ffc2d8d72ea69242ad4
Deleted: sha256:3072318e40ebff019298a59290e615ad6170a651f3121c0e356dcf3dd7426136
Deleted: sha256:a69e3133dd3c0a81bd439120abb8f98e43c1581629896725b968db906c8fdfac
Deleted: sha256:6d9498fd63c38c4b0b9bbc563087b4bc164b2fb5211832a8d43c60a9692a7f84
Deleted: sha256:f68ef921efae588b3dd5cc466a1ca9c94c24785f1fa9420bea15ecc2dedbe781
Untagged: hello-world:latest
Untagged: hello-world@sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
#查看剩余的docker镜像
[root@VM-8-14-centos docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
容器命令
说明:我们有了镜像才可以创建容器,linux,下载一个centos镜像来测试学习
docker pull centos
新建容器并启动
docker run [可选参数] image
#参数说明
--name="Name" 容器名字 tomcat1 tomcat2 用于区分容器
-d 后台方式运行
-it 使用交互方式运行,进入容器查看内容
-p 指定容器的端口 -p 8080:8080
-p ip:主机端口:容器端口
-p 主机端口:容器端口(常用)
-p 容器端口
容器端口
#测试 启动并进入容器
[root@VM-8-14-centos docker]# docker run -it centos /bin/bash
[root@ac71b5898083 /]#
[root@ac71b5898083 /]# ls #查看容器内的centos,基础版本,很多命令都不完善
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
#退出容器命令
[root@9af1a7b253ec /]# exit
exit
[root@VM-8-14-centos /]#
列出所有运行的容器
#docker ps 命令
#列出当前正在运行的容器
-a #列出当前正在运行的容器+历史运行过的容器
-n=? #显示最近创建的容器
-q #只显示容器的编号
[root@VM-8-14-centos /]# docker ps #运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@VM-8-14-centos /]# docker ps -a #运行过的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9af1a7b253ec centos "/bin/bash" About a minute ago Exited (0) About a minute ago happy_nash
ac71b5898083 centos "/bin/bash" 3 minutes ago Exited (0) 2 minutes ago sleepy_sutherland
e1c59d0e993b d1165f221234 "/hello" 24 hours ago Exited (0) 24 hours ago quizzical_albattani
[root@VM-8-14-centos /]#
退出容器
exit #容器直接停止退出
Ctrl+P+Q #不停止退出
删除容器
docker rm 容器id #删除指定的容器,不能删除正在运行的容器,如果要强制删除就rm -f
docker rm -f $(docker ps -aq) #删除所有的容器
docker ps -a -q|xargs docker rm #删除所有的容器
启动和停止容器的操作
docker start 容器id #启动容器
docker restart 容器id #重启容器
docker stop 容器id #停止当前正在运行的容器
docker kill 容器id #强制停止当前容器
常用其他命令
后台启动容器
#命令docker run -d 镜像名!
[root@VM-8-14-centos /]# docker run -d centos
#问题 docker ps 发现centos 停止了
#docker容器使用后台运行,就必须要有一个前台进程,否则docker发现没有应用,就会自动停止
#例如nginx,容器启动后,发现自己没有提供服务,就会立即停止,就是没有程序了
查看日志
[root@VM-8-14-centos /]# docker run -d centos /bin/bash -c "while true;do echo fanxu;sleep 1;done"
88e36a8819f26f5d12a8fd658adfbb97ed60901a71a8d878a0d8174b98b72dd7
[root@VM-8-14-centos /]# docker logs -tf --tail 10 88e36a8819f2
2021-08-18T14:17:58.098503211Z fanxu
2021-08-18T14:17:59.100849355Z fanxu
2021-08-18T14:18:00.103158743Z fanxu
2021-08-18T14:18:01.105462026Z fanxu
2021-08-18T14:18:02.107828632Z fanxu
查看容器中进程信息
[root@VM-8-14-centos /]# docker top 81d323846d11
UID PID PPID C STIME TTY TIME CMD
root 20586 20568 0 22:20 pts/0 00:00:00 /bin/bash
查看镜像的源数据
#命令
docker inspect 容器id
[root@VM-8-14-centos /]# docker inspect 81d323846d11
[
{
"Id": "81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02",
"Created": "2021-08-18T14:20:55.98150614Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 21525,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-08-18T14:24:47.97344561Z",
"FinishedAt": "2021-08-18T14:21:26.415512597Z"
},
"Image": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55",
"ResolvConfPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/hostname",
"HostsPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/hosts",
"LogPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02-json.log",
"Name": "/sad_dewdney",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e-init/diff:/var/lib/docker/overlay2/ceeaa5c3fbacd569a80e013cd1a6b907befa0d99540989b93b8815c9bf1451bb/diff",
"MergedDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/merged",
"UpperDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/diff",
"WorkDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "81d323846d11",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "centos",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20201204",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "23b5413c3d4ff11d5cb5b1d93acd35c3132ca7e5183fc178179f89436b0dda23",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/23b5413c3d4f",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "e834842300b4afe5cbf75789ec9e534acc1d62235e9efd0cbd305dbcf9c8e488",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "603e3599e40881a802fb09405c7bb535241e86cd1ae9671bad557dead6b9a31b",
"EndpointID": "e834842300b4afe5cbf75789ec9e534acc1d62235e9efd0cbd305dbcf9c8e488",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
进入当前运行的容器
# 使用容器的时候一般都是使用后台方式运行的,需要进入容器,更改配置
#第一种方式
[root@VM-8-14-centos ~]# docker start 81d323846d11
81d323846d11
[root@VM-8-14-centos ~]# docker exec -it 81d323846d11 /bin/bash
[root@81d323846d11 /]# ps
PID TTY TIME CMD
15 pts/1 00:00:00 bash
29 pts/1 00:00:00 ps
#第二种方式 进入后会执行当前的代码
[root@VM-8-14-centos ~]# docker attach 81d323846d11
You cannot attach to a stopped container, start it first
[root@VM-8-14-centos ~]# ps
PID TTY TIME CMD
27536 pts/0 00:00:00 bash
30503 pts/0 00:00:00 ps
[root@VM-8-14-centos ~]#
#docker exec 进入容器后开启一个新的终端,可以在里操作
#docker attach 进入容器正在执行的终端,不会启动新的进程
从容器内拷贝文件到主机上
docker cp 容器id:容器内路径 目的的主机路径
[root@VM-8-14-centos home]# cd MUYU
[root@VM-8-14-centos MUYU]# touch muyu.java
[root@VM-8-14-centos MUYU]# ls
muyu.java
[root@VM-8-14-centos MUYU]# docker run -it centos /bin/bash
[root@a5627811a8d4 /]# cd /home
[root@a5627811a8d4 home]# ls
[root@a5627811a8d4 home]# touch test.java
[root@a5627811a8d4 home]# ls
test.java
[root@a5627811a8d4 home]# exit
exit
[root@VM-8-14-centos MUYU]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5627811a8d4 centos "/bin/bash" 36 seconds ago Exited (0) 5 seconds ago quirky_gauss
#将docker中的文件复制到主机中
[root@VM-8-14-centos MUYU]# docker cp a5627811a8d4:/home/test.java /home/MUYU
[root@VM-8-14-centos MUYU]# ls
muyu.java test.java
测试学习
安装Nginx
搜索
[root@VM-8-14-centos ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 15344 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2060 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 816 [OK]
安装
[root@VM-8-14-centos ~]# docker pull nginx
启动
[root@VM-8-14-centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest dd34e67e3371 3 days ago 133MB
centos latest 300e315adb2f 8 months ago 209MB
[root@VM-8-14-centos ~]# docker run -d --name nginx01 -p 3344:80 nginx
4ec8e9008334917e67cf84134d09191c1fc2200cf1177d38eb590b3f010fa1a4
[root@VM-8-14-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4ec8e9008334 nginx "/docker-entrypoint.…" 4 seconds ago Up 3 seconds 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01
[root@VM-8-14-centos ~]# curl localhost:3344
#启动成功
<!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查看配置文件
[root@VM-8-14-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4ec8e9008334 nginx "/docker-entrypoint.…" 9 minutes ago Up 9 minutes 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01
[root@VM-8-14-centos ~]# docker exec -it nginx01 /bin/bash
root@4ec8e9008334:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@4ec8e9008334:/# cd /etc/nginx/
root@4ec8e9008334:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
安装tomcat
搜索
[root@VM-8-14-centos ~]# docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 3099 [OK]
tomee Apache TomEE is an all-Apache Java EE certif… 92 [OK]
安装
[root@VM-8-14-centos ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
1cfaf5c6f756: Pull complete
c4099a935a96: Pull complete
f6e2960d8365: Pull complete
dffd4e638592: Pull complete
a60431b16af7: Pull complete
4869c4e8de8d: Pull complete
9815a275e5d0: Pull complete
c36aa3d16702: Pull complete
cc2e74b6c3db: Pull complete
1827dd5c8bb0: Pull complete
Digest: sha256:1af502b6fd35c1d4ab6f24dc9bd36b58678a068ff1206c25acc129fb90b2a76a
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
运行
#-it进入容器运行,--rm代表退出容器即删除容器 用于测试,此方法可不下载tomcat
[root@VM-8-14-centos ~]# docker run -it --rm tomcat
...
21-Aug-2021 06:36:39.306 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
21-Aug-2021 06:36:39.404 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [2282] milliseconds
21-Aug-2021 06:36:39.624 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
21-Aug-2021 06:36:39.624 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.52]
21-Aug-2021 06:36:39.659 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
21-Aug-2021 06:36:39.690 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [278] milliseconds
#这是正常启动的方法
[root@VM-8-14-centos ~]# docker run -d -p 3344:8080 --name tomcat02 tomcat
bc039740fd76c153013464b04f44baaaedb70d796317ad076a71a91e192b3073
#启动成功
查看配置文件
#进入容器内部
[root@VM-8-14-centos ~]# docker exec -it tomcat02 /bin/bash
root@bc039740fd76:/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@bc039740fd76:/usr/local/tomcat# cd webapps
root@bc039740fd76:/usr/local/tomcat/webapps# ls
#发现没有东西,我们再去与之相似的webapps.dist下看看
root@bc039740fd76:/usr/local/tomcat/webapps# cd ..
root@bc039740fd76:/usr/local/tomcat# cd webapps.dist/
root@bc039740fd76:/usr/local/tomcat/webapps.dist# ls
#可以发现webapps下的东西都在webapps.dist中
ROOT docs examples host-manager manager
root@bc039740fd76:/usr/local/tomcat/webapps.dist#
#将所有webapps.dist中的东西复制到webapps中
root@bc039740fd76:/usr/local/tomcat/webapps.dist# cd ..
root@bc039740fd76:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@bc039740fd76:/usr/local/tomcat# cd webapps.dist/
#刷新页面
安装elastic search
安装并启动ElasticSearch
[root@VM-8-14-centos ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.
查看耗费内存以及cpu情况
[root@VM-8-14-centos ~]# docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
f7a2b56b00f8 elasticsearch 0.26% 1.244GiB / 1.795GiB 69.29% 1.6kB / 1.3kB 212MB / 729kB 43
#占用比例太高,需要对其进行优化
优化内存占比后启动
[root@VM-8-14-centos ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2
[root@VM-8-14-centos ~]# docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
c738385bb639 elasticsearch 99.49% 218.3MiB / 1.795GiB 11.88% 656B / 0B 94.9MB / 246kB 18
#使用的内存降下来了
测试连接
[root@VM-8-14-centos ~]# curl localhost:9200
{
"name" : "c738385bb639",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "XV6FxEBqQyyNwuUv9lMCdQ",
"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"
}
可视化
portainer
docker run -d -p 8082:9000 \
--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
运行后访问ip的8082端口,然后确认密码,点击本地即可。
会进到这样一个页面,分别代表堆栈、容器、镜像、卷和网络,还可以看见一些主机的信息,关于docker的事件等。
镜像
是一种轻量级,可执行的独立软件包,用来打包软件运行环境和基于运行环境开发的软件,它包含运行某个软件所需的所有内容。
所有的应用,直接打包docker镜像,就可以直接跑起来
如何得到镜像:
- 从远程仓库下载
- 朋友拷贝给你
- 自己制作一个镜像DockerFile
unionFS(联合文件系统):union文件系统,是一种 分层、轻量级并且高性能的文件系统,它支持对文件系统的修改作为一次提交来一层层的叠加。多个镜像中的不同层可以共享,这样极大的节省了空间,并且提高了效率
Commit镜像
docker commit 提交容器成为一个新的副本
#和git类似
docker commit -m=“提交的描述信息” -a=“作者” 容器id 目标镜像名:[Tag]
例子
先启动一个tomcat容器,然后进入webapps,发现里边没有内容,于是将webapps.list中的内容复制到webapps,然后退出,这
[root@VM-8-14-centos ~]# docker run -it -p 8082:8080 tomcat
root@476cde880bd2:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@476cde880bd2:/usr/local/tomcat/webapps# exit
exit
[root@VM-8-14-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
476cde880bd2 tomcat "catalina.sh run" 5 minutes ago Up 5 minutes 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp cool_panini
[root@VM-8-14-centos ~]# docker commit -a="fanxu" -m="add webapps to tomcat" 476cde880bd2 tomweb
sha256:1ced5f187f8030a5cba41833859c4f99beccc33b7b548989e0e335760bf4dd09