# 官方使用:docker run -it --rm xxx,一般用来测试,用完即删
docker run -it --rm tomcat:9.0
[root@kuangshen ~]# docker pull tomcat:9.0
9.0: Pulling from library/tomcat
Digest: sha256:a5abf192aceed45620dbb2e09f8abdec2b96108b86365a988c85e753c28cd36b
Status: Image is up to date for tomcat:9.0
docker.io/library/tomcat:9.0
[root@kuangshen ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 9f1d21c1025a 6 hours ago 448MB
nginx latest 4cdc5dd7eaad 13 days ago 133MB
tomcat 9.0 36ef696ea43d 2 weeks ago 667MB
hello-world latest d1165f221234 4 months ago 13.3kB
centos latest 300e315adb2f 7 months ago 209MB
[root@kaungshen ~]# docker run -d -p 3355:8080 --name tomcat02 tomcat
f3aec02f5533454773218e4e289ad9229ab9f160e89739ba226297191836c98f
docker: Error response from daemon: driver failed programming external connectivity on endpoint tomcat02 (5118e3e626714935383b2ff7cf343dbfc94281824b6f3ca0072ce238fa04d1b7): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3355 -j DNAT --to-destination 172.17.0.3:8080 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).
[root@kaungshen ~]# systemctl restart docker
[root@kaungshen ~]# docker run -d -p 3355:8080 --name tomcat02 tomcat:9.0
docker: Error response from daemon: Conflict. The container name "/tomcat02" is already in use by container "f3aec02f5533454773218e4e289ad9229ab9f160e89739ba226297191836c98f". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@kaungshen ~]# docker run -d -p 3355:8080 --name tomcat03 tomcat:9.0
935fc18daf1b592706044a4afe6e53cf4fab79b2801d2196bb675eae094633f8
[root@kaungshen ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
935fc18daf1b tomcat:9.0 "catalina.sh run" 14 seconds ago Up 13 seconds 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat03
f3aec02f5533 tomcat "catalina.sh run" 2 minutes ago Created tomcat02
f026ab817956 tomcat:9.0 "catalina.sh run" 3 minutes ago Created tomcat01
b34c7392ddac nginx "/docker-entrypoint.…" 3 hours ago Exited (0) 42 seconds ago nginx01
9cd4a264f0ab centos "/bin/bash" 3 hours ago Exited (0) 3 hours ago angry_cannon
[root@kaungshen ~]# docker rm f026ab817956
f026ab817956
[root@kaungshen ~]# docker rm f3aec02f5533
f3aec02f5533
报错:docker: Error response from daemon: driver failed programming external connectivity on endpoint tomcat01 (2e7b60107161f46927e4eff3d168b394317f525d8f9b8aef4ad6e2effbde048d): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3355 -j DNAT --to-destination 172.17.0.3:8080 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).
重启docker: systemctl restart docker
删除容器历史: docker ps -a
重新后台启动: docker run -d -p 3355:8080 --name tomcat03 tomcat:9.0
[root@kuangshen ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
935fc18daf1b tomcat:9.0 "catalina.sh run" 6 minutes ago Up 6 minutes 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat03
[root@kuangshen ~]# docker exec -it tomcat03 /bin/bash
root@935fc18daf1b:/usr/local/tomcat# ls
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work
root@935fc18daf1b:/usr/local/tomcat#
发现问题:1.Linux命令变少了,2.没有webapps,有webapps.dist,此时访问也无法请求到资源
思考
:es 暴露的端口很多
es 十分耗内存
es 的数据一般需要放置到安全目录!挂载
$ docker network create somenetwork
$ docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:tag
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e “discovery.type=single-node” elasticsearch:7.13.3
root@935fc18daf1b:/usr/local/tomcat/webapps.dist# exit
exit
[root@kuangshen ~]# docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.13.3
Unable to find image 'elasticsearch:7.13.3' locally
7.13.3: Pulling from library/elasticsearch
7a0437f04f83: Already exists
f84ddaec3c24: Pull complete
4b215d2787ba: Pull complete
f7b99f869fb7: Pull complete
0f89a98794ee: Pull complete
8f5687ec0173: Pull complete
3ce9ef48be20: Pull complete
Digest: sha256:759533051d0d5c67f7b09c8655ea00af3a8f15f98e2df4ea76ff2b47967488a5
Status: Downloaded newer image for elasticsearch:7.13.3
dc74dfdab1b81cff86dc940cc67d0685073bea5869c8252d6d1151f16ccecc25
[root@kuangshen ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc74dfdab1b8 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" 26 seconds ago Up 23 seconds 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
935fc18daf1b tomcat:9.0 "catalina.sh run" 31 minutes ago Up 31 minutes 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat03
[root@kuangshen ~]#
测试访问:curl localhost:9200
[root@kuangshen ~]# curl localhost:9200
{
"name" : "dc74dfdab1b8",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "a61i2LakTSuGBg_mTQNwjg",
"version" : {
"number" : "7.13.3",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "5d21bea28db1e89ecc1f66311ebdec9dc3aa7d64",
"build_date" : "2021-07-02T12:06:10.804015202Z",
"build_snapshot" : false,
"lucene_version" : "8.8.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
服务器都卡了,赶紧停掉:
[root@kuangshen ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc74dfdab1b8 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" 10 minutes ago Up 10 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
935fc18daf1b tomcat:9.0 "catalina.sh run" 42 minutes ago Up 41 minutes 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat03
[root@kuangshen ~]# docker stop dc74dfdab1b8
dc74dfdab1b8
[root@kuangshen ~]#
修改配置文件 -e 配置环境修改
docker run -d --name elasticsearch02 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.13.3
下载启动
//docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock --privileged=true portainer/portainer
//如果直接使用官网的命令会出问题,请用下条命令,下一章会讲docker的卷技术
docker run -d --name portainer -p 8088:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
[root@kuangshen ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc62c2254935 portainer/portainer "/portainer" 6 minutes ago Created reverent_haibt
6288eddd94b3 portainer/portainer "/portainer" 18 minutes ago Exited (2) 9 seconds ago quirky_neumann
34fb3c029026 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" 57 minutes ago Up 57 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch02
dc74dfdab1b8 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" About an hour ago Exited (143) About an hour ago elasticsearch
935fc18daf1b tomcat:9.0 "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat03
b34c7392ddac nginx "/docker-entrypoint.…" 5 hours ago Exited (0) 2 hours ago nginx01
9cd4a264f0ab centos "/bin/bash" 5 hours ago Exited (0) 5 hours ago angry_cannon
[root@kuangshen ~]# docker rm fc62c2254935 6288eddd94b3 dc74dfdab1b8
fc62c2254935
6288eddd94b3
dc74dfdab1b8
[root@kuangshen ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34fb3c029026 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" 58 minutes ago Up 58 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch02
935fc18daf1b tomcat:9.0 "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp tomcat03
b34c7392ddac nginx "/docker-entrypoint.…" 5 hours ago Exited (0) 2 hours ago nginx01
9cd4a264f0ab centos "/bin/bash" 5 hours ago Exited (0) 5 hours ago angry_cannon
[root@kuangshen ~]# docker run -d --name portainer -p 8088:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
c6a750b3039fe049ce9561ae43c65a9e5026c6c66f3109b8749e19127721b86a
[root@kuangshen ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c6a750b3039f portainer/portainer "/portainer" 6 seconds ago Up 6 seconds 0.0.0.0:8088->9000/tcp, :::8088->9000/tcp portainer
34fb3c029026 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" 59 minutes ago Up 59 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch02
935fc18daf1b tomcat:9.0 "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3355->8080/tcp, :::3355->8080/tcp
docker commit -m="提交的描述信息" -a="作者" 容器id 目标镜像名:[tag]
思考
:[root@kuangshen~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
95cd72311ab6 tomcat "catalina.sh run" About a minute ago Up About a minute 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp recursing_morse
c6a750b3039f portainer/portainer "/portainer" 34 minutes ago Up 34 minutes 0.0.0.0:8088->9000/tcp, :::8088->9000/tcp portainer
34fb3c029026 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" 2 hours ago Up 2 hours 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch02
[root@kuangshen ~]# docker exec -it 95cd72311ab6 /bin/bash
root@95cd72311ab6:/usr/local/tomcat# ls
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work
root@95cd72311ab6:/usr/local/tomcat# cp -r webapps.dist/ webapps/
root@95cd72311ab6:/usr/local/tomcat# cd webapps/
root@95cd72311ab6:/usr/local/tomcat/webapps# ls
webapps.dist
root@95cd72311ab6:/usr/local/tomcat/webapps# rm -rf webapps.dist/
root@95cd72311ab6:/usr/local/tomcat/webapps# ls
root@95cd72311ab6:/usr/local/tomcat/webapps# cd ..
root@95cd72311ab6:/usr/local/tomcat# cp -r webapps.dist/* webapps/
root@95cd72311ab6:/usr/local/tomcat# cd webapps/
root@95cd72311ab6:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
root@95cd72311ab6:/usr/local/tomcat/webapps#
上述操作是将tomcat镜像中的webapp.dist文件夹的内容复制到webapps
此操作能够访问到Tomcat资源
思考:提交自己的Tomcat
[root@kuangshen ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@kuangshen ~]# firewall-cmd --reload
success
[root@kuangshen ~]# docker os
docker: 'os' is not a docker command.
See 'docker --help'
[root@kuangshen ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
95cd72311ab6 tomcat "catalina.sh run" 19 minutes ago Up 19 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp recursing_morse
c6a750b3039f portainer/portainer "/portainer" 52 minutes ago Up 52 minutes 0.0.0.0:8088->9000/tcp, :::8088->9000/tcp portainer
34fb3c029026 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" 2 hours ago Up 2 hours 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch02
[root@kuangshen ~]# docker commit -a="swl" -m="add webapps app" 95cd72311ab6 tomcat02:1.0
sha256:95e5803af67684a375fb10461403e17a48f6425323664ba0f188878a67d9ca74
[root@kuangshen ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat02 1.0 95e5803af676 6 seconds ago 672MB
mysql 5.7 9f1d21c1025a 12 hours ago 448MB
nginx latest 4cdc5dd7eaad 13 days ago 133MB
tomcat 9.0 36ef696ea43d 2 weeks ago 667MB
tomcat latest 36ef696ea43d 2 weeks ago 667MB
elasticsearch 7.13.3 84840c8322fe 2 weeks ago 1.02GB
redis latest 08502081bff6 3 weeks ago 105MB
portainer/portainer latest 580c0e4e98b0 4 months ago 79.1MB
hello-world latest d1165f221234 4 months ago 13.3kB
centos latest 300e315adb2f 7 months ago 209MB
-思考解答