本文主要总结了一些docker的基本使用命令以及几个使用docker的练习。最后介绍了一个图形化管理docker的工具。
一般来说,我们可以构建一个Dcokerfile文件,并从这个文件
build
一个镜像(images);
镜像通过run
运行起来得到容器,对于一个容器;我们可以使之启动/重启/停止/强制停止start/restart/stop/kill
,容器运行时执行命令会改变容器中的状态,可以通过commit
再将容器提交形成镜像;
我们可以通过pull/push
从远程仓库中拉取/上传镜像,也可以通过save/load
在本地保存或者加载镜像。
docker version #显示docker的版本信息
docker info #显示关于docker的更加详细的信息
docker --help #查看docker帮助文档
docker的官方帮助文档:https://docs.docker.com/engine/reference
docker images
docker images#查看当前本地的镜像信息
root@10:/home/kate/Desktop# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4bb46517cac3 13 days ago 133MB
debian latest ee11c54e6bb7 3 weeks ago 114MB
hello-world latest bf756fb1ae65 7 months ago 13.3kB
#解释
REPOSITORY :镜像名称
TAG:标签
IMAGE ID:镜像id
CREATED:镜像创建时间
#可选
-a -all #显示所有镜像
-q #只显示镜像id
docker search
root@10:/home/kate/Desktop# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 13663 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1866 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 782 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 127
bitnami/nginx Bitnami nginx Docker Image 89 [OK]
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 88 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 82
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 75 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 59 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 53 [OK]
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 40
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 32 [OK]
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 17
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 15
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 14
raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 13 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 12 [OK]
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
mailu/nginx Mailu nginx frontend 7 [OK]
bitwarden/nginx The Bitwarden nginx web server acting as a r… 7
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 6 [OK]
wodby/nginx Generic nginx 1 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 1 [OK]
root@10:/home/kate/Desktop#
#查看docker search的帮助文档
root@10:/home/kate/Desktop# docker search --help
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images
Options:
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print search using a Go template
--limit int Max number of search results (default 25)
--no-trunc Don't truncate output
#进行过滤
root@10:/home/kate/Desktop# docker search --filter=STARs=100 nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 13663 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1866 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 782 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 127
docker pull
# docker pull 镜像名[:tag]
root@10:/home/kate/Desktop# docker pull mysql
Using default tag: latest #没有写tag字段的话,默认下载最新的版本
latest: Pulling from library/mysql
bf5952930446: Already exists
8254623a9871: Pull complete
938e3e06dac4: Pull complete
ea28ebf28884: Pull complete
f3cef38785c2: Pull complete
894f9792565a: Pull complete
1d8a57523420: Pull complete
6c676912929f: Pull complete
ff39fdb566b4: Pull complete
fff872988aba: Pull complete
4d34e365ae68: Pull complete
7886ee20621e: Pull complete
Digest: sha256:c358e72e100ab493a0304bda35e6f239db2ec8c9bb836d8a427ac34307d074ed #签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest #下载地址
#以下命令等价
docker pull mysql
docker pull docker.io/library/mysql:latest
#指定版本下载
docker pull mysql:5.7
docker rmi
root@10:/home/kate/Desktop# docker rmi 0d64f46acfd1 #指定镜像id或者镜像名称删除
Untagged: mysql:latest
Untagged: mysql@sha256:c358e72e100ab493a0304bda35e6f239db2ec8c9bb836d8a427ac34307d074ed
Deleted: sha256:0d64f46acfd1af4ee6a162f80c6e07e843761bf14d412060023bf0e69e720fb4
Deleted: sha256:308fb4d64e5d57094fcd70bd946f9f842a1de6b596a4807787f01dc181c76b18
Deleted: sha256:fbc8e9508f704f46bfe3607ce4523aac7758757a9752a44a40221c2d353b7147
Deleted: sha256:d55db5e278c81c9cf5b51cc63f5ba9c5d9a616f6e28f9ce25b3545ff58298a89
Deleted: sha256:c2596316288a83e50e7e922d18b5f86b8ce34915c6f58c239f093cb514016538
Deleted: sha256:cfe5cd376e0ee9cb83864690a8971646a774ed189bda11f5a39e8bb0e71d77f9
Deleted: sha256:904abdc2d0bea0edbb1a8171d1a1353fa6de22150a9c5d81358799a5b6c38c8d
Deleted: sha256:d26f7649f78cf789267fbbca8aeb234932e230109c728632c6b9fbc60ca5591b
Deleted: sha256:7fcf7796e23ea5b42eb3bbd5bec160ba5f5f47ecb239053762f9cf766c143942
Deleted: sha256:826130797a5760bcd2bb19a6c6d92b5f4860bbffbfa954f5d3fc627904a76e9d
Deleted: sha256:53e0181c63e41fb85bce681ec8aadfa323cd00f70509107f7001a1d0614e5adf
Deleted: sha256:d6854b83e83d7eb48fb0ef778c58a8b839adb932dd036a085d94a7c2db98f890
root@10:/home/kate/Desktop# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4bb46517cac3 13 days ago 133MB
debian latest ee11c54e6bb7 3 weeks ago 114MB
hello-world latest bf756fb1ae65 7 months ago 13.3kB
root@10:/home/kate/Desktop# docker rmi -f 镜像id 镜像id 镜像id
#删除多个镜像
root@10:/home/kate/Desktop# docker rmi -f $(docker images -aq) #删除所有镜像
下述代码从镜像
debian
运行容器,进行一些修改后,从修改后的容器生成镜像debian01
root@10:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4bb46517cac3 13 days ago 133MB
debian latest ee11c54e6bb7 3 weeks ago 114MB
portainer/portainer latest 62771b0b9b09 5 weeks ago 79.1MB
hello-world latest bf756fb1ae65 7 months ago 13.3kB
root@10:~# docker run -it --name="debian-01" debian
root@c32fb00614ff:/# cd /home/
root@c32fb00614ff:/home# ls
root@c32fb00614ff:/home# touch test.sh
root@c32fb00614ff:/home# exit
exit
root@10:~# docker ps -aq
c32fb00614ff
66747533b19f
8f557fe4d5d4
bdd701179836
d7c5a8d3c59f
82dd061952b0
00aebed36b72
4c208c7d48e4
f3f57a014e53
root@10:~# docker commit -a "kate" -m "add test.sh " c32fb00614ff debian01
sha256:3d171a46602b76618bf58f9170dd4d0b9a1be664167067fd1fc26d146d087512
root@10:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
debian01 latest 3d171a46602b 4 seconds ago 114MB
<none> <none> 93bf5d148c59 48 seconds ago 114MB
nginx latest 4bb46517cac3 13 days ago 133MB
debian latest ee11c54e6bb7 3 weeks ago 114MB
portainer/portainer latest 62771b0b9b09 5 weeks ago 79.1MB
hello-world latest bf756fb1ae65 7 months ago 13.3kB
- 在Dockerhub上注册账号
- docker login -u -p 在本地登录
- 上传镜像
root@10:# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: kate123wong
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
上传之前要用
tag
给镜像加标签,并以dockerhub上账号名/镜像名:标签
的形式。
root@10:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test 1.0 f76966f4fcfb 23 hours ago 54.5MB
root@10:~# docker tag d3f33308de61 kate123wong/test:1.0
root@10:~# docker push kate123wong/test:1.0
The push refers to repository [docker.io/kate123wong/test]
c64e6dcb312b: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
90973c6a901f: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
a1b4adfcde54: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
7738072db152: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
577d6e8669d2: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
1f454ef9ca7b: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
88fb19d1f005: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
93ea2be4f8b9: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
f95727b06764: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
767f936afb51: Mounted from ctftraining/ciscn_2019_northern_china_day2_web1
1.0: digest: sha256:b98c48dd25b9cb4f5f67b025412c42663d93924b33d14282a4797141db0ce6c9 size: 2409
说明:有了镜像才可以运行容器。
docker pull debian
docker run
:新建容器并启动
docker run [可选参数] image
# 参数说明
--name="name" #给容器命名 tomcat01 tomcat02 用来区分容器。
-d 后台运行
-it 前台运行
-p 指定端口
-P 随机指定端口
root@10:~# docker run -it debian
root@4c208c7d48e4:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@4c208c7d48e4:/#
#从容器退出到主机
root@4c208c7d48e4:/# exit
root@10:~#
docker ps
:列出当前正在运行的容器
docker ps #列出当前正在运行的容器
-a #显示所有运行过的容器
-q #只显示容器id
root@10:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
root@10:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c208c7d48e4 debian "bash" 2 minutes ago Exited (0) About a minute ago reverent_hofstadter
f3f57a014e53 debian "bash" 21 hours ago Exited (255) 58 minutes ago nostalgic_saha
root@10:~# docker ps -aq
4c208c7d48e4
f3f57a014e53
root@10:~#
exit #停止并退出容器
Ctrl+P+Q #退出容器不停止容器
docker rm 容器id #删除容器
docker rm -f 容器id #强制删除正在运行的容器
docker rm -f $(docker ps -aq) #强制删除所有的容器
docker ps -aq | xargs docker rm #删除所有的容器
docker start 容器id #启动容器
docker restart 容器id #重启容器
docker stop 容器id #停止容器
docker kill 容器id # 强制杀死/停止容器
docker run -d
:后台启动容器
root@10:~# docker run -d nginx --name="comcat01"
00aebed36b7226473d8a3ac9fc1c8887a33a7fdfa6af50a3f700f4b563dfcc49
root@10:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
root@10:~#
后台启动容器后,用docker ps
查看时,发现启动的容器并没有运行,原因是:后台启动容器后,如果自己没有提供服务,就是自杀。
docker exec -it 容器id /bin/bash
:进入容器并打开一个新的终端
docker attach 容器id
: 进入一个正在运行的容器
root@10:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82dd061952b0 debian "bash" About a minute ago Up About a minute wonderful_snyder
root@10:~# docker exec -it 82dd061952b0 /bin/bash
root@82dd061952b0:/# read escape sequence
root@10:~# docker attach 82dd061952b0
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=28 ttl=52 time=43.7 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=29 ttl=52 time=40.7 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=30 ttl=52 time=38.1 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=31 ttl=52 time=43.1 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=32 ttl=52 time=38.1 ms
^C
--- www.a.shifen.com ping statistics ---
32 packets transmitted, 32 received, 0% packet loss, time 699ms
rtt min/avg/max/mdev = 37.040/38.941/48.396/2.397 ms
root@82dd061952b0:/# exit
docker logs 容器id
输出该容器的所有操作日志
root@10:~# docker logs 4c208c7d48e4
root@4c208c7d48e4:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@4c208c7d48e4:/# exit
exit
root@10:~#
#参数说明
-- tail number #显示number条日志
docker top 容器id
从容器内部拷贝文件到主机
docker cp
:拷贝
docker cp 容器id:文件位置 目标目录
root@10:~# docker run -it debian
root@d7c5a8d3c59f:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@d7c5a8d3c59f:/# cd /home/
root@d7c5a8d3c59f:/home# touch test.java
root@d7c5a8d3c59f:/home# ls
test.java
root@d7c5a8d3c59f:/home# exit
exit
root@10:~# docker ps -aq
d7c5a8d3c59f
82dd061952b0
00aebed36b72
4c208c7d48e4
f3f57a014e53
root@10:~# docker cp d7c5a8d3c59f:/home/test.java /home
root@10:~# cd /home/
root@10:/home# ls
kate test.java
docker inspect 容器id
:查看容器元数据
root@10:~# docker inspect 4c208c7d48e4
[
{
"Id": "4c208c7d48e45bf2c902a4fec1e16e111947ffcbc6c7d8ae342cc9d9ea37e363",
"Created": "2020-08-27T05:40:27.989013679Z",
"Path": "bash",
"Args": [],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-08-27T05:40:29.806388875Z",
"FinishedAt": "2020-08-27T05:40:58.711734001Z"
},
"Image": "sha256:ee11c54e6bb7b1c022d7a43aaee00eac776367a7a1adb7746a79757fae175a5e",
"ResolvConfPath": "/var/lib/docker/containers/4c208c7d48e45bf2c902a4fec1e16e111947ffcbc6c7d8ae342cc9d9ea37e363/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/4c208c7d48e45bf2c902a4fec1e16e111947ffcbc6c7d8ae342cc9d9ea37e363/hostname",
"HostsPath": "/var/lib/docker/containers/4c208c7d48e45bf2c902a4fec1e16e111947ffcbc6c7d8ae342cc9d9ea37e363/hosts",
"LogPath": "/var/lib/docker/containers/4c208c7d48e45bf2c902a4fec1e16e111947ffcbc6c7d8ae342cc9d9ea37e363/4c208c7d48e45bf2c902a4fec1e16e111947ffcbc6c7d8ae342cc9d9ea37e363-json.log",
"Name": "/reverent_hofstadter",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"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,
"Capabilities": null,
"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/f5fec29cb9fedf2c3b8f433a114b200ca05f25899e8fa84b2e0364dce8874c31-init/diff:/var/lib/docker/overlay2/72e1bdaeab86927fb3c3299ad55e6bf39c47ef99ce05e0fc6ececd45f91b1a8a/diff",
"MergedDir": "/var/lib/docker/overlay2/f5fec29cb9fedf2c3b8f433a114b200ca05f25899e8fa84b2e0364dce8874c31/merged",
"UpperDir": "/var/lib/docker/overlay2/f5fec29cb9fedf2c3b8f433a114b200ca05f25899e8fa84b2e0364dce8874c31/diff",
"WorkDir": "/var/lib/docker/overlay2/f5fec29cb9fedf2c3b8f433a114b200ca05f25899e8fa84b2e0364dce8874c31/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "4c208c7d48e4",
"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": [
"bash"
],
"Image": "debian",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "31ad4dd546d4eb164e2a662f4af825eba8cec757ebb6416d8449a70c8b8084e5",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
},
"SandboxKey": "/var/run/docker/netns/31ad4dd546d4",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "039e46dd00a090d03580a59e09acb92b5d2839972b029031d236ca8e3b368e2b",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
安装并运行nginx
启动容器;指定端口:nginx服务器的80端口映射到本地的2233端口;本地访问测试:
root@10:/home# docker run -d --name="nginx01" -p 2233:80 nginx
bdd70117983693b7302b8c1b7531a78342a16ce2ceb20bfaa3c8865acdb41554
root@10:/home# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bdd701179836 nginx "/docker-entrypoint.…" 5 seconds ago Up 3 seconds 0.0.0.0:2233->80/tcp nginx01
root@10:/home# curl localhost:2233
<!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>
root@10:/home#
root@10:/home# docker exec -it ningx01 /bin/bash
root@bdd701179836:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@bdd701179836:/# cd /etc/nginx/
root@bdd701179836:/etc/nginx# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
root@bdd701179836:/etc/nginx#
安装部署Tomcat
docker run -it -rm tomcat:9.0
:用完即删除容器
docker pull tomcat #拉取镜像
docker run -d -p 1314:8080 --name="tomcat01" tomcat #后台启动并运行镜像、为容器起别名为tomcat01
docker exec -it comcat01 /bin/bash #进入容器
#运行时发现问题:linux命令变少了;没有webapps。原因:镜像源的原因,将所有不用的都剔除掉。
安装 es
root@10:~ 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
docker stats 容器id #查看该容器占用内存的情况。
加参数-e ES_JAVA_OPTS="-Xms64m -Xmx512m"
的原因:限制内存,es十分消耗内存。
#安装+运行命令
docker run -d -p 8080:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --name prtainer01 portainer/portainer
curl localhost:8080
本期写了一些docker的基本命令,主要是镜像和容器的操作还有一些常用其他命令,但是最详细的手册永远是官网哦~
您的点赞转发将是对我最大的支持~